Skip to content

Commit 798dd6b

Browse files
author
Jamie Smith
authored
Fix off-by-1 error in memap's symbol-contained-in-memory-bank check, clean up some linker script stuff (#362)
* Fix off-by-1 error in memap's symbol-contained-in-memory-bank check, clean up some linker script stuff * Update comment * One more typo
1 parent d5278aa commit 798dd6b

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_GCC_ARM/LPC1768.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ SECTIONS
159159
* values to stack symbols later */
160160
.stack_dummy (NOLOAD):
161161
{
162-
*(.stack)
162+
. += STACK_SIZE;
163163
} > RAM
164164

165165
/* Set stack top to end of RAM, and stack limit move down by

tools/cmake/mbed_set_linker_script.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_de
9595
# add linker script only for tests
9696
if(MBED_IS_STANDALONE)
9797
target_link_options(${TARGET}
98-
INTERFACE
99-
"-T" "${LINKER_SCRIPT_PATH}"
100-
)
98+
INTERFACE
99+
"-T" "${LINKER_SCRIPT_PATH}"
100+
)
101+
set_property(TARGET ${TARGET} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH})
101102
endif()
102103
endforeach()
103104

@@ -150,5 +151,6 @@ function(mbed_set_custom_linker_script target new_linker_script_path)
150151
PRIVATE
151152
"-T" "${CUSTOM_LINKER_SCRIPT_PATH}"
152153
)
154+
set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS ${CUSTOM_LINKER_SCRIPT_PATH})
153155

154156
endfunction(mbed_set_custom_linker_script)

tools/cmake/mbed_target_functions.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,14 @@ function(mbed_set_post_build target)
128128
get_target_property(POST_BUILD_TARGET_LINK_LIBRARIES ${target} LINK_LIBRARIES)
129129
if("mbed-os" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
130130
get_target_property(LINKER_SCRIPT_PATH mbed-os LINKER_SCRIPT_PATH)
131-
target_link_options(${target}
132-
PRIVATE
133-
"-T" "${LINKER_SCRIPT_PATH}"
134-
)
135131
elseif("mbed-baremetal" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
136132
get_target_property(LINKER_SCRIPT_PATH mbed-baremetal LINKER_SCRIPT_PATH)
137-
target_link_options(${target}
138-
PRIVATE
139-
"-T" "${LINKER_SCRIPT_PATH}"
140-
)
141133
else()
142134
message(FATAL_ERROR "Target ${target} used with mbed_set_post_build() but does not link to mbed-os or mbed-baremetal!")
143135
endif()
136+
137+
target_link_options(${target} PRIVATE "-T" "${LINKER_SCRIPT_PATH}")
138+
set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS ${LINKER_SCRIPT_PATH})
144139
else()
145140
message(STATUS "${target} uses custom linker script ${ARGV1}")
146141
mbed_set_custom_linker_script(${target} ${ARGV1})

tools/python/memap/memap.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
from prettytable import PrettyTable, HEADER
6464
from jinja2 import FileSystemLoader, StrictUndefined
6565
from jinja2.environment import Environment
66-
from future.utils import with_metaclass
6766

6867

6968
# Be sure that the tools directory is in the search path
@@ -127,7 +126,7 @@ def _add_symbol_to_memory_banks(self, symbol_name: str, symbol_start_addr: int,
127126
for banks in self.memory_banks.values():
128127
for bank_info in banks:
129128
if bank_info.contains_addr(symbol_start_addr):
130-
if bank_info.contains_addr(end_addr):
129+
if bank_info.contains_addr(end_addr - 1): # end_addr is the first address past the end of the symbol so we subtract 1 here
131130
# Symbol fully inside this memory bank
132131
bank_info.used_size += size
133132

@@ -146,7 +145,7 @@ def add_symbol(self, symbol_name: str, object_name: str, start_addr: int, size:
146145
""" Adds information about a symbol (e.g. a function or global variable) to the data structures.
147146
148147
Positional arguments:
149-
symbol_name - Descriptive name of the symbol, e.g. ".text.some_function"
148+
symbol_name - Descriptive name of the symbol, e.g. ".text.some_function" or "*fill*"
150149
object_name - name of the object file containing the symbol
151150
start addr - start address of symbol
152151
size - the size of the symbol being added
@@ -234,7 +233,9 @@ class _GccParser(_Parser):
234233

235234
# Gets the input section name from the line, if it exists.
236235
# Input section names are always indented 1 space.
237-
RE_INPUT_SECTION_NAME = re.compile(r'^ (\.\w+\.?\w*\.?\w*)') # Note: This allows up to 3 dots... hopefully that's enough...
236+
# Note: This allows up to 3 dots... hopefully that's enough...
237+
# It can also capture "*fill*" instead of something that looks like a section name.
238+
RE_INPUT_SECTION_NAME = re.compile(r'^ ((?:\.\w+\.?\w*\.?\w*)|(?:\*fill\*))')
238239

239240
ALL_SECTIONS = (
240241
_Parser.SECTIONS
@@ -844,7 +845,7 @@ def parse(self, mapfile: str, toolchain: str, memory_banks_json_path: str | None
844845

845846
def main():
846847
"""Entry Point"""
847-
version = '0.4.0'
848+
version = '1.0.0'
848849

849850
# Parser handling
850851
parser = ArgumentParser(

0 commit comments

Comments
 (0)