This is an archive of the discontinued LLVM Phabricator instance.

[Clang][IA] support -generate-unused-section-symbols={yes|no}
Needs RevisionPublic

Authored by nickdesaulniers on Apr 15 2022, 1:33 PM.

Details

Reviewers
MaskRay
Summary

GNU binutils has added support for explicitly retaining (yes option) or
dropping (no option) STT_SECTION symbols from the symbols table via
assembler option -generate-unused-section-symbols={yes|no}.

Add support to clang (-Wa,-generate-unused-section-symbols={yes|no})
and llvm-mc.

This feature might be used by the Linux kernel.
https://lore.kernel.org/linux-toolchains/YllUqPK4CWZeHku8@hirez.programming.kicks-ass.net/
This has been supported by GNU binutils since 2.36.
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2022, 1:33 PM
nickdesaulniers requested review of this revision.Apr 15 2022, 1:33 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 15 2022, 1:33 PM
MaskRay added a comment.EditedApr 15 2022, 1:55 PM

I wish we don't do this.
https://sourceware.org/pipermail/binutils/2022-March/119940.html (RFC: GAS: Add option to generate unused section symbols):

This problem was fixed in the kernel (and backported by distros to their kernels if binutils was updated); it's fairly simplistic changes.

I don't see the need for returning (optionally) to the old behaviour again. I mean, at the time, when 2.36 came out, sure, the patch might have made sense, but now?

LLVM integrated assembler has stayed the current behavior for many years.
Having the feature would only benefit the next major release 15.0.0. Versions 11~14 are still supported, so some conditional compilation is needed, making the feature less useful.

I am not familiar with the tool mentioned on The trouble with __weak and objtool got worse, but I think making the tool work with discarded STT_SECTION symbols isn't likely to cause much trouble.

MaskRay added a comment.EditedApr 15 2022, 2:08 PM

Add support to clang (-Wa,-generate-unused-section-symbols={yes|no}) and llvm-mc.

This feature might be used by the Linux kernel. https://lore.kernel.org/linux-toolchains/YllUqPK4CWZeHku8@hirez.programming.kicks-ass.net/

This has been supported by GNU binutils since 2.36. https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8

AFAICT GNU as never gets an option named -generate-unused-section-symbols=yes.
It just has a quirk that interprets nearly all -g* options as -g, which indicates generation of some compile units for ELF symbols with the help of .size directives.
It's very different from generating unused section symbols.

MaskRay requested changes to this revision.Apr 22 2022, 12:00 AM

Add support to clang (-Wa,-generate-unused-section-symbols={yes|no}) and llvm-mc.

This feature might be used by the Linux kernel. https://lore.kernel.org/linux-toolchains/YllUqPK4CWZeHku8@hirez.programming.kicks-ass.net/

This has been supported by GNU binutils since 2.36. https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8

AFAICT GNU as never gets an option named -generate-unused-section-symbols=yes.
It just has a quirk that interprets nearly all -g* options as -g, which indicates generation of some compile units for ELF symbols with the help of .size directives.
It's very different from generating unused section symbols.

Latest GNU as added an error for an unknown -g option.

This revision now requires changes to proceed.Apr 22 2022, 12:00 AM