Skip to content

feat: Add support for the DISCARD section in linker scripts - #1978

Merged
davidlattimore merged 5 commits into
wild-linker:mainfrom
vishruth-thimmaiah:discard
May 25, 2026
Merged

feat: Add support for the DISCARD section in linker scripts#1978
davidlattimore merged 5 commits into
wild-linker:mainfrom
vishruth-thimmaiah:discard

Conversation

@vishruth-thimmaiah

@vishruth-thimmaiah vishruth-thimmaiah commented May 25, 2026

Copy link
Copy Markdown
Member

Support discarding sections that are marked as discardable with the /DISCARD/ command in linker scripts.

Closes: #1829

Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
@davidlattimore davidlattimore changed the title Add support for the DISCARD section in linker scripts feat: Add support for the DISCARD section in linker scripts May 25, 2026
Comment thread libwild/src/layout_rules.rs Outdated
//#DiffIgnore:segment.LOAD.RX.alignment
//#DiffIgnore:segment.LOAD.RWX.alignment
//#DoesNotContain:DISCARD
//#DoesNotContain:.text

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want to test whether we emit the symbol foo or not. From a quick experiment, it looks like wild and lld don't emit foo, while GNU ld weirdly does. So if we went that route ("NoSym:foo"), then we'd likely need to disable GNU ld and enable lld for the test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making foo static stops ld from emitting it in .dynsym, so we should be able to keep ld as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static that isn't referenced could be eliminated by the compiler, so might make the test pass even without /DISCARD/ support

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I've updated the test to only use lld.

Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
@davidlattimore
davidlattimore merged commit f78ceab into wild-linker:main May 25, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add linker-script support for /DISCARD/ pseudo-section

2 participants