Skip to content

Support excluded sections#1077

Merged
davidlattimore merged 3 commits intowild-linker:mainfrom
lqd:no-gc
Sep 12, 2025
Merged

Support excluded sections#1077
davidlattimore merged 3 commits intowild-linker:mainfrom
lqd:no-gc

Conversation

@lqd
Copy link
Copy Markdown
Contributor

@lqd lqd commented Sep 10, 2025

This adds support for sections to exclude, flagged "e", as described in #1073.

As expected from the description, with this PR a rust helloworld is indeed 1.3MB, and 8.1MB without it as the .llvmbc sections are not discarded.

I'm not sure about the test. I don't really know what I'm doing and wasn't able to test how the issue describes: I kept hitting errors about loaded sections while trying make a shared object. I'm also not sure if it should be using --no-gc-sections. To be clear, I have verified it fails without the last commit discarding excluded sections.

@mati865
Copy link
Copy Markdown
Member

mati865 commented Sep 10, 2025

Hello there!

Could you run clang-format -i /__w/wild/wild/wild/tests/sources/*.{c,cc,h} so the CI shows the real issue?

I'm also not sure if it should be using --no-gc-sections

Yeah, Wild unlike other linkers performs sections GC by default. For this test we need to disable it, to make sure the section is discarded even without GC.
I can look into it tomorrow.

Copy link
Copy Markdown
Member

@davidlattimore davidlattimore left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

Comment thread wild/tests/sources/exclude-section.c Outdated
Comment thread wild/tests/sources/exclude-section.s Outdated
@lqd
Copy link
Copy Markdown
Contributor Author

lqd commented Sep 11, 2025

Could you run clang-format

Done.

I've also pushed forcing --no-gc-sections and the more minimal test structure David suggested. I imagine turning it into a shared object would also remove the need to set up the runtime, have a _start symbol and some .text, etc?

@davidlattimore
Copy link
Copy Markdown
Member

Yep, if you wanted to go the shared object route, I think you'd add -shared as a link argument, then add //#RunEnabled:false. You could also move all the test directives into the .s file and delete the .c file. There are some other shared-object-only tests if you need something to reference. e.g. dynamic-bss-only.c. I'm not sure there are any others that are assembly-only, so that might be a first.

I think it might also be possible to remove the Arch line, since I think the assembly you've got is likely portable to other architectures as it doesn't actually use any assembly instructions.

@mati865
Copy link
Copy Markdown
Member

mati865 commented Sep 11, 2025

The closest assembly only test would be wild/tests/sources/basic-comdat-1.s (found using rg "//#" wild/tests/sources/*.s).

@lqd
Copy link
Copy Markdown
Contributor Author

lqd commented Sep 11, 2025

Thanks! I've adapted the test to copy basic-comdat.s's structure, which looked very much like exactly what was needed.

@davidlattimore
Copy link
Copy Markdown
Member

section.got
wild Section missing
ld OK

Looks like GNU ld is generating a GOT section on aarch64. You could add //#DiffIgnore:section.got

@lqd
Copy link
Copy Markdown
Contributor Author

lqd commented Sep 12, 2025

Done. Hopefully this will pass CI now, but it doesn't like me enough to run automatically.

@lqd
Copy link
Copy Markdown
Contributor Author

lqd commented Sep 12, 2025

(thanks mati :)

@davidlattimore davidlattimore merged commit 9ad33b6 into wild-linker:main Sep 12, 2025
23 checks passed
@davidlattimore
Copy link
Copy Markdown
Member

Done. Hopefully this will pass CI now, but it doesn't like me enough to run automatically.

Now that you've had a PR merged, I think any subsequent PRs won't need approval for actions to run.

Thanks for your contribution!

@lqd lqd deleted the no-gc branch September 12, 2025 08:27
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.

3 participants