This is an archive of the discontinued LLVM Phabricator instance.

[ELFObjectWriter] emit STT_SECTION symbols for sections
AbandonedPublic

Authored by nickdesaulniers on Dec 23 2020, 2:57 PM.

Details

Summary

Effectively a revert of r239045 ("Omit unused section symbols from the symbol table.")

By not emitted STT_SECTION symbols for each section, external utilities
that rely on address calculations from these symbols break when moving
from GNU as (via -no-integrated-as) to Clang's integrated assembler.

Particularly, the Linux kernel's objtool utility which is used to
embed custom format unwind info for x86 into the kernel image.

To improve compatibility with GAS, do not intentionally omit these
section symbols.

Increases binary sizes slightly due to additional symbol entries in the
symbol table.

r239045 cites readability of tests as a reason for the optimization. We
can fix that by using -NEXT less aggressively in tests.

Link: https://github.com/ClangBuiltLinux/linux/issues/669
Link: https://github.com/ClangBuiltLinux/linux/issues/872
Link: https://github.com/ClangBuiltLinux/linux/issues/1209

Diff Detail

Event Timeline

nickdesaulniers requested review of this revision.Dec 23 2020, 2:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2020, 2:57 PM
nickdesaulniers planned changes to this revision.Dec 23 2020, 2:58 PM

TODO: fix failing tests:

  • lld/test/ELF/error-handling-script-linux.test
  • llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_relocations.s
nickdesaulniers edited the summary of this revision. (Show Details)Dec 23 2020, 2:58 PM
nickdesaulniers added a subscriber: void.

I understand that it is a pain for Linux kernel's objtool but r239045 ("Omit unused section symbols from the symbol table.") is a really/really desired enhancement and size optimization.
GNU as's behavior is inferior here. For a -ffunction-sections or -fdata-sections build, there can be many sections. Wasting sizeof(Elf64_Shdr)=64 bytes (STT_SECTION not used by a relocation, which is very common) on each section is really not acceptable.
objtool should take pain and fix whatever issues due to this. I'll happy to defend MC's behavior for any such instance in Linux kernel's mailing lists.

I thought I filed a GNU as feature request but it seems that I haven't (perhaps I just mentioned this on a binutils@sourceware.org thread but did not actually file a feature request). I'll file a feature request.

jcai19 added a subscriber: jcai19.Dec 23 2020, 3:30 PM

GNU as (x86/powerpc) has omitted unused STT_SECTION. Some Linux kernel has been worked around for the objtool limitation. This can probably be closed.

nickdesaulniers abandoned this revision.Jan 25 2021, 10:55 AM