feat: Support symbol definitions in linker script#1307
Merged
lapla-cogito merged 7 commits intoNov 16, 2025
Conversation
lapla-cogito
commented
Nov 15, 2025
Comment on lines
+10
to
+11
| defsym_start_aaa = start_aaa; | ||
| defsym_addr = 0x1234; |
Member
Author
There was a problem hiding this comment.
Sample output from the tested binary:
(▰╹◡╹)❯ readelf -s wild/tests/build/linker-script.c-default-host.ld
Symbol table '.dynsym' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000150 0 NOTYPE GLOBAL DEFAULT 6 start_aaa
2: 0000000000000150 0 NOTYPE GLOBAL DEFAULT 6 defsym_start_aaa
3: 0000000000000154 0 NOTYPE GLOBAL DEFAULT 6 end_bar
4: 0000000000000148 0 NOTYPE GLOBAL DEFAULT 6 start_bar
5: 0000000000001234 0 NOTYPE GLOBAL DEFAULT ABS defsym_addr
Symbol table '.symtab' contains 12 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS linker-script.c
2: 0000000000000148 4 OBJECT LOCAL DEFAULT 6 foo1
3: 000000000000014c 4 OBJECT LOCAL DEFAULT 6 baz1
4: 0000000000000150 4 OBJECT LOCAL DEFAULT 6 aaa1
5: 0000000000000000 0 FILE LOCAL DEFAULT ABS
6: 0000000000000158 0 OBJECT LOCAL DEFAULT 7 _DYNAMIC
7: 0000000000000148 0 NOTYPE GLOBAL DEFAULT 6 start_bar
8: 0000000000001234 0 NOTYPE GLOBAL DEFAULT ABS defsym_addr
9: 0000000000000150 0 NOTYPE GLOBAL DEFAULT 6 start_aaa
10: 0000000000000150 0 NOTYPE GLOBAL DEFAULT 6 defsym_start_aaa
11: 0000000000000154 0 NOTYPE GLOBAL DEFAULT 6 end_bar
(▰╹◡╹)❯ readelf -s wild/tests/build/linker-script.c-default-host.wild
Symbol table '.dynsym' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000002838 0 NOTYPE GLOBAL DEFAULT 7 defsym_start_aaa
2: 000000000000283c 0 NOTYPE GLOBAL DEFAULT 7 end_bar
3: 0000000000001234 0 NOTYPE GLOBAL DEFAULT ABS defsym_addr
4: 0000000000002838 0 NOTYPE GLOBAL DEFAULT 7 start_aaa
5: 0000000000002830 0 NOTYPE GLOBAL DEFAULT 7 start_bar
Symbol table '.symtab' contains 12 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS linker-script.c
2: 0000000000002830 4 OBJECT LOCAL DEFAULT 7 foo1
3: 0000000000002834 4 OBJECT LOCAL DEFAULT 7 baz1
4: 0000000000002838 4 OBJECT LOCAL DEFAULT 7 aaa1
5: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 1 __ehdr_start
6: 0000000000002620 0 NOTYPE GLOBAL DEFAULT 6 _DYNAMIC
7: 0000000000002830 0 NOTYPE GLOBAL DEFAULT 7 start_bar
8: 0000000000002838 0 NOTYPE GLOBAL DEFAULT 7 start_aaa
9: 000000000000283c 0 NOTYPE GLOBAL DEFAULT 7 end_bar
10: 0000000000002838 0 NOTYPE GLOBAL DEFAULT 7 defsym_start_aaa
11: 0000000000001234 0 NOTYPE GLOBAL DEFAULT ABS defsym_addr
davidlattimore
left a comment
Member
There was a problem hiding this comment.
Great to have this!
At the moment, the distinction between --symdef and the equivalent from a linker script is maintained all the way through to the write phase. Would it be possible to add the relevant symbols to the prelude earlier on, then treat them the same from then on? i.e have the code that deals with these symbols in layout and writing be the same regardless of whether the symbol came from --symdef or a linker script.
Member
Author
|
Thanks, top-level symbol definitions specified in linker scripts are now merged during the prelude phase. This also simplifies the processing performed by |
davidlattimore
approved these changes
Nov 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
--defsymsupport added in #1300, we can extend this to support top-level symbol definitions in linker scripts as well.