mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 16:19:52 +00:00
Don't get confused with sections whose section number is reserved.
It is perfectly possible for SHNDX to contain indexes that have the same value as reserved st_shndx values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240544 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -401,7 +401,7 @@ public:
|
|||||||
|
|
||||||
uint64_t getNumSections() const;
|
uint64_t getNumSections() const;
|
||||||
uintX_t getStringTableIndex() const;
|
uintX_t getStringTableIndex() const;
|
||||||
ELF::Elf64_Word getSymbolTableIndex(const Elf_Sym *symb) const;
|
ELF::Elf64_Word getExtendedSymbolTableIndex(const Elf_Sym *symb) const;
|
||||||
const Elf_Ehdr *getHeader() const { return Header; }
|
const Elf_Ehdr *getHeader() const { return Header; }
|
||||||
const Elf_Shdr *getSection(const Elf_Sym *symb) const;
|
const Elf_Shdr *getSection(const Elf_Sym *symb) const;
|
||||||
const Elf_Shdr *getSection(uint32_t Index) const;
|
const Elf_Shdr *getSection(uint32_t Index) const;
|
||||||
@@ -510,10 +510,10 @@ void ELFFile<ELFT>::LoadVersionMap() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
ELF::Elf64_Word ELFFile<ELFT>::getSymbolTableIndex(const Elf_Sym *symb) const {
|
ELF::Elf64_Word
|
||||||
if (symb->st_shndx == ELF::SHN_XINDEX)
|
ELFFile<ELFT>::getExtendedSymbolTableIndex(const Elf_Sym *symb) const {
|
||||||
return ExtendedSymbolTable.lookup(symb);
|
assert(symb->st_shndx == ELF::SHN_XINDEX);
|
||||||
return symb->st_shndx;
|
return ExtendedSymbolTable.lookup(symb);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ template <class ELFT>
|
|||||||
std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
|
std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
|
||||||
uint64_t &Result) const {
|
uint64_t &Result) const {
|
||||||
const Elf_Sym *ESym = getSymbol(Symb);
|
const Elf_Sym *ESym = getSymbol(Symb);
|
||||||
switch (EF.getSymbolTableIndex(ESym)) {
|
switch (ESym->st_shndx) {
|
||||||
case ELF::SHN_COMMON:
|
case ELF::SHN_COMMON:
|
||||||
case ELF::SHN_UNDEF:
|
case ELF::SHN_UNDEF:
|
||||||
Result = UnknownAddress;
|
Result = UnknownAddress;
|
||||||
@@ -383,11 +383,10 @@ uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Symb) const {
|
|||||||
EIter == EF.begin_symbols() || EIter == EF.begin_dynamic_symbols())
|
EIter == EF.begin_symbols() || EIter == EF.begin_dynamic_symbols())
|
||||||
Result |= SymbolRef::SF_FormatSpecific;
|
Result |= SymbolRef::SF_FormatSpecific;
|
||||||
|
|
||||||
if (EF.getSymbolTableIndex(ESym) == ELF::SHN_UNDEF)
|
if (ESym->st_shndx == ELF::SHN_UNDEF)
|
||||||
Result |= SymbolRef::SF_Undefined;
|
Result |= SymbolRef::SF_Undefined;
|
||||||
|
|
||||||
if (ESym->getType() == ELF::STT_COMMON ||
|
if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
|
||||||
EF.getSymbolTableIndex(ESym) == ELF::SHN_COMMON)
|
|
||||||
Result |= SymbolRef::SF_Common;
|
Result |= SymbolRef::SF_Common;
|
||||||
|
|
||||||
if (isExportedToOtherDSO(ESym))
|
if (isExportedToOtherDSO(ESym))
|
||||||
|
|||||||
107
test/MC/ELF/many-sections-3.s
Normal file
107
test/MC/ELF/many-sections-3.s
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
|
||||||
|
// RUN: llvm-readobj -t %t | FileCheck --check-prefix=SYMBOLS %s
|
||||||
|
// RUN: llvm-nm %t | FileCheck --check-prefix=NM %s
|
||||||
|
|
||||||
|
// Test that symbol a has a section that could be confused with common (0xFFF2)
|
||||||
|
// SYMBOLS: Name: a
|
||||||
|
// SYMBOLS-NEXT: Value: 0x0
|
||||||
|
// SYMBOLS-NEXT: Size: 0
|
||||||
|
// SYMBOLS-NEXT: Binding: Local (0x0)
|
||||||
|
// SYMBOLS-NEXT: Type: None (0x0)
|
||||||
|
// SYMBOLS-NEXT: Other: 0
|
||||||
|
// SYMBOLS-NEXT: Section: bar (0xFFF2)
|
||||||
|
// SYMBOLS-NEXT: }
|
||||||
|
|
||||||
|
// Test that we don't get confused
|
||||||
|
// NM: 0000000000000000 r a
|
||||||
|
|
||||||
|
.macro gen_sections4 x
|
||||||
|
.section a\x
|
||||||
|
.section b\x
|
||||||
|
.section c\x
|
||||||
|
.section d\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections8 x
|
||||||
|
gen_sections4 a\x
|
||||||
|
gen_sections4 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections16 x
|
||||||
|
gen_sections8 a\x
|
||||||
|
gen_sections8 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections32 x
|
||||||
|
gen_sections16 a\x
|
||||||
|
gen_sections16 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections64 x
|
||||||
|
gen_sections32 a\x
|
||||||
|
gen_sections32 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections128 x
|
||||||
|
gen_sections64 a\x
|
||||||
|
gen_sections64 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections256 x
|
||||||
|
gen_sections128 a\x
|
||||||
|
gen_sections128 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections512 x
|
||||||
|
gen_sections256 a\x
|
||||||
|
gen_sections256 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections1024 x
|
||||||
|
gen_sections512 a\x
|
||||||
|
gen_sections512 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections2048 x
|
||||||
|
gen_sections1024 a\x
|
||||||
|
gen_sections1024 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections4096 x
|
||||||
|
gen_sections2048 a\x
|
||||||
|
gen_sections2048 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections8192 x
|
||||||
|
gen_sections4096 a\x
|
||||||
|
gen_sections4096 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections16384 x
|
||||||
|
gen_sections8192 a\x
|
||||||
|
gen_sections8192 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro gen_sections32768 x
|
||||||
|
gen_sections16384 a\x
|
||||||
|
gen_sections16384 b\x
|
||||||
|
.endm
|
||||||
|
|
||||||
|
gen_sections32768 a
|
||||||
|
gen_sections16384 b
|
||||||
|
gen_sections8192 c
|
||||||
|
gen_sections4096 d
|
||||||
|
gen_sections2048 e
|
||||||
|
gen_sections1024 f
|
||||||
|
gen_sections512 g
|
||||||
|
gen_sections256 h
|
||||||
|
gen_sections128 i
|
||||||
|
gen_sections64 j
|
||||||
|
gen_sections32 k
|
||||||
|
gen_sections8 l
|
||||||
|
gen_sections4 m
|
||||||
|
|
||||||
|
.section foo
|
||||||
|
.section bar, "a"
|
||||||
|
|
||||||
|
a:
|
||||||
@@ -156,9 +156,7 @@ getSectionNameIndex(const ELFO &Obj, typename ELFO::Elf_Sym_Iter Symbol,
|
|||||||
SectionName = "Reserved";
|
SectionName = "Reserved";
|
||||||
else {
|
else {
|
||||||
if (SectionIndex == SHN_XINDEX)
|
if (SectionIndex == SHN_XINDEX)
|
||||||
SectionIndex = Obj.getSymbolTableIndex(&*Symbol);
|
SectionIndex = Obj.getExtendedSymbolTableIndex(&*Symbol);
|
||||||
assert(SectionIndex != SHN_XINDEX &&
|
|
||||||
"getSymbolTableIndex should handle this");
|
|
||||||
const typename ELFO::Elf_Shdr *Sec = Obj.getSection(SectionIndex);
|
const typename ELFO::Elf_Shdr *Sec = Obj.getSection(SectionIndex);
|
||||||
SectionName = errorOrDefault(Obj.getSectionName(Sec));
|
SectionName = errorOrDefault(Obj.getSectionName(Sec));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user