[PATCH] D72899: [MC] Set sh_link to 0 if the associated symbol is undefined

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 13:46:10 PST 2020


MaskRay added a comment.

I think we have 3 choices to represent the linked-to section.

1. Allow SHF_LINK_ORDER with sh_link=0. The ELF spec has a requirement about the link order[1] (original semantics of SHF_LINK_ORDER). I think allowing sh_link=0 should be vaguely compatible because we can interpret sh_link=0 as referencing the first section SHN_UNDEF.
2. Add a non-GC-root dummy section. This is a bit awkward to implement in MC because we have to pick a section name. The section may be combined with other normal sections with the same name. We need to be careful and not cause an "incompatible section flags" error (lld specific).
3. Add a GC-root dummy section, for example, SHT_INIT_ARRAY, and name it .init_array, so that it can be comined with other .init_array sections. Note other sh_link!=0 sections can be garbage collected.

I want to avoid 3 because it causes a behavior difference. 2 can make the linker logic straightforward but the awkwardness remains in the assembler. If we ever support -r --gc-sections, note that the linked-to section can still be collected while the metadata section is alive. We will still face the problem how to represent such metadata sections whose linked-to sections are collected.

Considering all the above, I am inclined to do 1 (this patch).

[1]: SHF_LINK_ORDER - This flag adds special ordering requirements for link editors. The requirements apply if the sh_link field of this section's header references another section (the linked-to section). If this section is combined with other sections in the output file, it must appear in the same relative order with respect to those sections, as the linked-to section appears with respect to sections the linked-to section is combined with.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72899/new/

https://reviews.llvm.org/D72899





More information about the llvm-commits mailing list