[ELF] Add sh_link field to .ARM.exidx sections for relocatable links
When doing a relocatable link the .ARM.exidx sections with the
SHF_LINK_ORDER flag set need to set the sh_link field to the executable
section they describe. We find the appropriate OutputSection by
following the sh_link field of the .ARM.exidx InputSections.
The getOutputSectionName() function rules make sure that when there are
multiple .ARM.exidx InputSections in an OutputSection they all have the
same sh_link field.
Differential revision: https://reviews.llvm.org/D25825
llvm-svn: 284820
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 66d44e2..27dc2be 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -933,9 +933,21 @@
template <class ELFT> void OutputSection<ELFT>::finalize() {
uint32_t Type = this->Header.sh_type;
- // SHF_LINK_ORDER only has meaning in relocatable objects
- if (!Config->Relocatable)
- this->Header.sh_flags &= ~SHF_LINK_ORDER;
+ if (this->Header.sh_flags & SHF_LINK_ORDER) {
+ if (!Config->Relocatable) {
+ // SHF_LINK_ORDER only has meaning in relocatable objects
+ this->Header.sh_flags &= ~SHF_LINK_ORDER;
+ }
+ else if (!this->Sections.empty()) {
+ // When doing a relocatable link we must preserve the link order
+ // dependency of sections with the SHF_LINK_ORDER flag. The dependency
+ // is indicated by the sh_link field. We need to translate the
+ // InputSection sh_link to the OutputSection sh_link, all InputSections
+ // in the OutputSection have the same dependency.
+ if (auto *D = this->Sections.front()->getLinkOrderDep())
+ this->Header.sh_link = D->OutSec->SectionIndex;
+ }
+ }
if (Type != SHT_RELA && Type != SHT_REL)
return;
this->Header.sh_link = Out<ELFT>::SymTab->SectionIndex;