[PATCH] D28950: [LLD][ELF] Correct sh_info for static symbol table
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 06:08:54 PST 2017
peter.smith created this revision.
Herald added a subscriber: nemanjai.
The sh_info field of the SHT_SYMTAB section holds the index for the first non-local symbol. When there are global symbols that are output with STB_LOCAL binding due to having hidden visibility or matching the local version from a version script, the calculated value of NumLocals + 1 does not account for them. This change adds in the number of local symbols that aren't covered by NumLocals.
I think that this property is of marginal use in an Executable/Shared object but there could be an ELF processing tool that could get confused if it skips all the local symbols in the file using the sh_info field.
The test updates are where we have a global symbol output with local binding and a check of a sh_info field.
I noticed this while working on support for synthetic local symbols. It feels like a bit of a hack, but if NumLocals is interpreted as number of locals stored outside of the SymbolTableSection::Symbols in Files it makes a bit more sense.
https://reviews.llvm.org/D28950
Files:
ELF/SyntheticSections.cpp
test/ELF/basic-mips.s
test/ELF/basic-ppc.s
Index: test/ELF/basic-ppc.s
===================================================================
--- test/ELF/basic-ppc.s
+++ test/ELF/basic-ppc.s
@@ -178,7 +178,7 @@
// CHECK-NEXT: Offset: 0x2038
// CHECK-NEXT: Size: 32
// CHECK-NEXT: Link: 9
-// CHECK-NEXT: Info: 1
+// CHECK-NEXT: Info: 2
// CHECK-NEXT: AddressAlignment: 4
// CHECK-NEXT: EntrySize: 16
// CHECK-NEXT: SectionData (
Index: test/ELF/basic-mips.s
===================================================================
--- test/ELF/basic-mips.s
+++ test/ELF/basic-mips.s
@@ -176,7 +176,7 @@
# CHECK-NEXT: Offset: 0x20010
# CHECK-NEXT: Size: 48
# CHECK-NEXT: Link: 10
-# CHECK-NEXT: Info: 1
+# CHECK-NEXT: Info: 2
# CHECK-NEXT: AddressAlignment: 4
# CHECK-NEXT: EntrySize: 16
# CHECK-NEXT: }
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1079,6 +1079,14 @@
return L.Symbol->symbol()->computeBinding() == STB_LOCAL &&
R.Symbol->symbol()->computeBinding() != STB_LOCAL;
});
+ // Last local symbol should account for Symbols with a computed Binding
+ // of STB_LOCAL as these will not be represented by NumLocals.
+ for(const SymbolTableEntry &S : Symbols) {
+ if (S.Symbol->symbol()->computeBinding() != STB_LOCAL)
+ return;
+ this->Info++;
+ this->OutSec->Info++;
+ }
return;
}
if (In<ELFT>::GnuHashTab)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28950.85128.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170120/67cc8e74/attachment.bin>
More information about the llvm-commits
mailing list