Difference between revisions of "Ld"
m (Memory Use Report - add link to Phillip Johnston article on correct memory use reporting via linker script crafting.) |
m (Add section on ELF files.) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 11: | Line 11: | ||
* https://lld.llvm.org/ELF/linker_script.html . . . LLVM linker documentation | * https://lld.llvm.org/ELF/linker_script.html . . . LLVM linker documentation | ||
| + | |||
| + | * https://allthingsembedded.com/post/2020-04-11-mastering-the-gnu-linker-script/ | ||
Use of 'KEEP' key word in linker scripts: | Use of 'KEEP' key word in linker scripts: | ||
| Line 77: | Line 79: | ||
* https://embeddedartistry.com/blog/2023/03/01/configuring-a-linker-script-for-accurate-linker-memory-usage-reporting/ | * https://embeddedartistry.com/blog/2023/03/01/configuring-a-linker-script-for-accurate-linker-memory-usage-reporting/ | ||
| + | |||
| + | == ELF Files == | ||
| + | |||
| + | May want to move ELF file format and reading notes to dedicated local page. Good intro tutorial: | ||
| + | |||
| + | * https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/ | ||
<!-- EOF --> | <!-- EOF --> | ||
Latest revision as of 14:12, 16 August 2025
GNU and LLVM linker notes.
Overview
This NN page a starting point for notes, links to external references and examples of `ld` linker scripts. As of page creation time 2024 Q1 there appear to be two major linker variants: GNU ld and LLVM linker implementation.
Introductory References
- https://lld.llvm.org/ELF/linker_script.html . . . LLVM linker documentation
Use of 'KEEP' key word in linker scripts:
How to place C global variables at a particular address:
- https://global.epson.com/products_and_drivers/semicon/products/micro_controller/pdf/lnk_03e.pdf
- https://stackoverflow.com/questions/39998485/how-to-access-variable-define-in-linker-script-in-c
A reference to gcc linker documentation:
2024-08-05 MON
Interesting linker script macro in one of Zephy's header files . . .
"
167
168 #ifndef BUILD_ASSERT
169 /* Compile-time assertion that makes the build to fail.
170 * Common implementation swallows the message.
171 */
172 #define BUILD_ASSERT(EXPR, MSG...) \
173 enum _CONCAT(__build_assert_enum, __COUNTER__) { \
174 _CONCAT(__build_assert, __COUNTER__) = 1 / !!(EXPR) \
175 }
176 #endif
177
178 /*
179 * This is meant to be used in conjunction with __in_section() and similar
180 * where scattered structure instances are concatenated together by the linker
181 * and walked by the code at run time just like a contiguous array of such
182 * structures.
183 *
184 * Assemblers and linkers may insert alignment padding by default whose
185 * size is larger than the natural alignment for those structures when
186 * gathering various section segments together, messing up the array walk.
187 * To prevent this, we need to provide an explicit alignment not to rely
188 * on the default that might just work by luck.
189 *
190 * Alignment statements in linker scripts are not sufficient as
191 * the assembler may add padding by itself to each segment when switching
192 * between sections within the same file even if it merges many such segments
193 * into a single section in the end.
194 */
195 #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type
196
"~/projects-sandbox/workspace-for-nexus/zephyr/include/zephyr/toolchain/common.h" 214 lines --99%--
Memory Use Report
The GNU linker `ld` can report memory usage based on linker scripts parsing. Following links to external articles go into some detail about this facility.
A good article by Phillip Johnston which describes how linker scripts provide for accurate or inaccurate memory use reporting:
ELF Files
May want to move ELF file format and reading notes to dedicated local page. Good intro tutorial: