From afd6c8e1d2a2c24595194879481987cec3b57f8a Mon Sep 17 00:00:00 2001 From: stijn Date: Thu, 8 Jan 2015 10:32:45 +0100 Subject: [PATCH] Remove obsolete bss-related code/build features GC for unix/windows builds doesn't make use of the bss section anymore, so we do not need the (sometimes complicated) build features and code related to it --- py/gc.c | 8 ++--- unix/Makefile | 15 ++------- unix/seg_helpers.c | 38 ---------------------- windows/Makefile | 1 - windows/bss.c | 71 ------------------------------------------ windows/init.c | 3 -- windows/mpconfigport.h | 8 ++--- 7 files changed, 7 insertions(+), 137 deletions(-) delete mode 100644 unix/seg_helpers.c delete mode 100644 windows/bss.c diff --git a/py/gc.c b/py/gc.c index 73a6ca8612..f3f5937cf3 100644 --- a/py/gc.c +++ b/py/gc.c @@ -695,11 +695,9 @@ void gc_dump_alloc_table(void) { case AT_FREE: c = '.'; break; /* this prints out if the object is reachable from BSS or STACK (for unix only) case AT_HEAD: { - extern char __bss_start, _end; - extern char *stack_top; c = 'h'; - void **ptrs = (void**)&__bss_start; - mp_uint_t len = ((mp_uint_t)&_end - (mp_uint_t)&__bss_start) / sizeof(mp_uint_t); + void **ptrs = (void**)(void*)&mp_state_ctx; + mp_uint_t len = offsetof(mp_state_ctx_t, vm.stack_top) / sizeof(mp_uint_t); for (mp_uint_t i = 0; i < len; i++) { mp_uint_t ptr = (mp_uint_t)ptrs[i]; if (VERIFY_PTR(ptr) && BLOCK_FROM_PTR(ptr) == bl) { @@ -709,7 +707,7 @@ void gc_dump_alloc_table(void) { } if (c == 'h') { ptrs = (void**)&c; - len = ((mp_uint_t)stack_top - (mp_uint_t)&c) / sizeof(mp_uint_t); + len = ((mp_uint_t)MP_STATE_VM(stack_top) - (mp_uint_t)&c) / sizeof(mp_uint_t); for (mp_uint_t i = 0; i < len; i++) { mp_uint_t ptr = (mp_uint_t)ptrs[i]; if (VERIFY_PTR(ptr) && BLOCK_FROM_PTR(ptr) == bl) { diff --git a/unix/Makefile b/unix/Makefile index e7e0d354b0..ea6590ac71 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -35,8 +35,8 @@ endif # if necessary override the value of 'CC' set in py/mkenv.mk ifeq ($(UNAME_S),Darwin) CC = clang -# Use clang syntax for map file and set osx specific flags -LDFLAGS_ARCH = -Wl,-order_file,$(BUILD)/order.def -Wl,-map,$@.map +# Use clang syntax for map file +LDFLAGS_ARCH = -Wl,-map,$@.map else # Use gcc syntax for map file LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref @@ -92,17 +92,6 @@ SRC_C = \ alloc.c \ $(SRC_MOD) -ifeq ($(UNAME_S),Darwin) -# Must be the last file in list of sources -SRC_C += seg_helpers.c - -# making seg_helpers.c rely on order.def will force order.def to be created -seg_helpers.c: $(BUILD)/order.def - -# create order.def in build directory -$(BUILD)/order.def: - $(Q)echo "seg_helpers.o: ___bss_start" > $@ -endif OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) diff --git a/unix/seg_helpers.c b/unix/seg_helpers.c deleted file mode 100644 index 1684f7a8f8..0000000000 --- a/unix/seg_helpers.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - This is a stub used to create the symbols __bss_start and _end in a Mach-O object file. - Thoses are needed by the GC, and should point to the start and end of the bss section. - We reach this goal by linking this file last (putting _end at the end...), and using an - order file (order.def) to move __bss_start at the start of bss. - - TODO: Some pragma to do it inline ? -*/ - -char __bss_start = 0; -char _end = 0; - diff --git a/windows/Makefile b/windows/Makefile index 5d5c7db790..342a2e4bcd 100644 --- a/windows/Makefile +++ b/windows/Makefile @@ -37,7 +37,6 @@ SRC_C = \ realpath.c \ init.c \ sleep.c \ - bss.c \ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) diff --git a/windows/bss.c b/windows/bss.c deleted file mode 100644 index 58509024f9..0000000000 --- a/windows/bss.c +++ /dev/null @@ -1,71 +0,0 @@ -/* -* This file is part of the Micro Python project, http://micropython.org/ -* -* The MIT License (MIT) -* -* Copyright (c) 2013, 2014 Damien P. George -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include "py/nlr.h" -#include "py/obj.h" -#include - -IMAGE_NT_HEADERS *header_from_memory(const char *module) { - BYTE *base_addr = (BYTE*)GetModuleHandleA(module); - IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER*)base_addr; - return (IMAGE_NT_HEADERS*)(base_addr + dos_header->e_lfanew); -} - -IMAGE_SECTION_HEADER *find_section(IMAGE_NT_HEADERS *nt_header, const char *name) { - int i; - IMAGE_SECTION_HEADER *section = IMAGE_FIRST_SECTION(nt_header); - for (i = 0; i < nt_header->FileHeader.NumberOfSections; ++i) { - if (strcmp((const char *)section->Name, name) == 0) { - return section; - } - ++section; - } - return NULL; -} - -void section_boundaries(IMAGE_NT_HEADERS *nt_header, IMAGE_SECTION_HEADER *section, char **start, char **end) { - if (section == NULL) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Could not lookup section boundaries")); - } - *start = (char*)(nt_header->OptionalHeader.ImageBase + section->VirtualAddress); - *end = *start + section->Misc.VirtualSize; -} - -void section_boundaries_from_module(const char *module, const char *section, char **start, char **end) { - IMAGE_NT_HEADERS *nt_header = header_from_memory(module); - IMAGE_SECTION_HEADER *dsection = find_section(nt_header, section); - section_boundaries(nt_header, dsection, start, end); -} - -char *bss_start = 0; -char *bss_end = 0; - -//MSVC has no __bss_start and _end but we can get accurate section info from the PE header. -//The standard .bss section is appended to the standard .data section however so it cannot -//be looked up by name. To deal with that we put all uPy static variables in a named section. -void getbss() { - section_boundaries_from_module(NULL, MICROPY_PORT_BSSSECTION, &bss_start, &bss_end); -} diff --git a/windows/init.c b/windows/init.c index 57f349ef89..a370c464e8 100644 --- a/windows/init.c +++ b/windows/init.c @@ -28,12 +28,9 @@ #include #include -extern void getbss(); - HANDLE hSleepEvent = NULL; void init() { - getbss(); hSleepEvent = CreateEvent(NULL, TRUE, FALSE, FALSE); #ifdef __MINGW32__ putenv("PRINTF_EXPONENT_DIGITS=2"); diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index 939010343a..aede68e21f 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -166,7 +166,8 @@ void msec_sleep(double msec); #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -// Put static/global variables in sections with a known name we can lookup for the GC +// Put static/global variables in sections with a known name +// This used to be required for GC, not the case anymore but keep it as it makes the map file easier to inspect // For this to work this header must be included by all sources, which is the case normally #define MICROPY_PORT_DATASECTION "upydata" #define MICROPY_PORT_BSSSECTION "upybss" @@ -183,8 +184,3 @@ void msec_sleep(double msec); int snprintf(char *dest, size_t count, const char *format, ...); #endif - -// MingW specifics -#ifdef __MINGW32__ -#define MICROPY_PORT_BSSSECTION ".bss" -#endif