mirror of
https://github.com/intel/llvm.git
synced 2026-01-21 20:53:29 +08:00
Fix the st_name of section symbols.
If it is non-zero then objdump will print an empty name when printing relocations against the section. llvm-svn: 295129
This commit is contained in:
@@ -768,7 +768,10 @@ template <class ELFT>
|
||||
StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
|
||||
: SyntheticSection<ELFT>(Dynamic ? (uintX_t)SHF_ALLOC : 0, SHT_STRTAB, 1,
|
||||
Name),
|
||||
Dynamic(Dynamic) {}
|
||||
Dynamic(Dynamic) {
|
||||
// ELF string tables start with a NUL byte.
|
||||
addString("");
|
||||
}
|
||||
|
||||
// Adds a string to the string table. If HashIt is true we hash and check for
|
||||
// duplicates. It is optional because the name of global symbols are already
|
||||
@@ -788,8 +791,6 @@ unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) {
|
||||
}
|
||||
|
||||
template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) {
|
||||
// ELF string tables start with NUL byte, so advance the pointer by one.
|
||||
++Buf;
|
||||
for (StringRef S : Strings) {
|
||||
memcpy(Buf, S.data(), S.size());
|
||||
Buf += S.size() + 1;
|
||||
|
||||
@@ -266,8 +266,7 @@ public:
|
||||
private:
|
||||
const bool Dynamic;
|
||||
|
||||
// ELF string tables start with a NUL byte, so 1.
|
||||
uintX_t Size = 1;
|
||||
uintX_t Size = 0;
|
||||
|
||||
llvm::DenseMap<StringRef, unsigned> StringMap;
|
||||
std::vector<StringRef> Strings;
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Address:
|
||||
# CHECK-NEXT: Offset
|
||||
# CHECK-NEXT: Size: 9
|
||||
# CHECK-NEXT: Size: 8
|
||||
# CHECK-NEXT: Link: 0
|
||||
# CHECK-NEXT: Info: 0
|
||||
# CHECK-NEXT: AddressAlignment: 1
|
||||
# CHECK-NEXT: EntrySize: 0
|
||||
# CHECK-NEXT: SectionData (
|
||||
# CHECK-NEXT: 0000: 00005F73 74617274 00 |.._start.|
|
||||
# CHECK-NEXT: 0000: 005F7374 61727400 |._start.|
|
||||
# CHECK-NEXT: )
|
||||
|
||||
# CHECK: Relocations [
|
||||
|
||||
28
lld/test/ELF/relocatable-symbol-name.s
Normal file
28
lld/test/ELF/relocatable-symbol-name.s
Normal file
@@ -0,0 +1,28 @@
|
||||
# REQUIRES: x86
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
|
||||
# RUN: ld.lld -r %t.o -o %t
|
||||
# RUN: llvm-readobj -t %t | FileCheck %s
|
||||
|
||||
# Test that the section symbol has st_name equal to zero. GNU objdump
|
||||
# requires this to print relocations against the section.
|
||||
|
||||
# CHECK: Symbols [
|
||||
# CHECK-NEXT: Symbol {
|
||||
# CHECK-NEXT: Name:
|
||||
# CHECK-NEXT: Value:
|
||||
# CHECK-NEXT: Size:
|
||||
# CHECK-NEXT: Binding:
|
||||
# CHECK-NEXT: Type:
|
||||
# CHECK-NEXT: Other:
|
||||
# CHECK-NEXT: Section:
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Symbol {
|
||||
# CHECK-NEXT: Name: (0)
|
||||
# CHECK-NEXT: Value:
|
||||
# CHECK-NEXT: Size:
|
||||
# CHECK-NEXT: Binding:
|
||||
# CHECK-NEXT: Type: Section
|
||||
# CHECK-NEXT: Other:
|
||||
# CHECK-NEXT: Section: .text
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: ]
|
||||
Reference in New Issue
Block a user