Difference between revisions of "Ld"

From Wiki at Neela Nurseries
Jump to: navigation, search
(Create new local page "ld" for linker script language notes and references.)
 
m (linker alignment macro in Zephyr.)
 
(4 intermediate revisions by the same user not shown)
Line 9: Line 9:
  
 
*  https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html
 
*  https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html
 +
 +
*  https://lld.llvm.org/ELF/linker_script.html . . . LLVM linker documentation
 +
 +
Use of 'KEEP' key word in linker scripts:
 +
 +
*  https://stackoverflow.com/questions/9827157/what-does-keep-mean-in-a-linker-script
 +
 +
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:
 +
 +
*  https://sourceware.org/binutils/docs/ld/Source-Code-Reference.html
  
 
<!-- odne komentar -->
 
<!-- odne komentar -->
  
 +
 +
2024-08-05 MON
 +
 +
Interesting linker script macro in one of Zephy's header files . . .
 +
<pre>
 +
"
 +
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%--
 +
 +
</pre>
  
  
 
<!-- EOF -->
 
<!-- EOF -->

Latest revision as of 18:01, 5 August 2024

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

Use of 'KEEP' key word in linker scripts:

How to place C global variables at a particular address:

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%--