Start adding support for common symbols.

For now this just recognizes the special section number.

llvm-svn: 246332
This commit is contained in:
Rafael Espindola
2015-08-28 21:26:51 +00:00
parent 0a92f86fe6
commit 51d4690b6e
4 changed files with 38 additions and 8 deletions

View File

@@ -99,11 +99,17 @@ SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable,
StringRef Name = *NameOrErr;
uint32_t SecIndex = Sym->st_shndx;
if (SecIndex == SHN_ABS)
switch (SecIndex) {
case SHN_ABS:
return new (Alloc) DefinedAbsolute<ELFT>(Name, *Sym);
if (SecIndex == SHN_XINDEX)
case SHN_UNDEF:
return new (Alloc) Undefined<ELFT>(Name, *Sym);
case SHN_COMMON:
return new (Alloc) DefinedCommon<ELFT>(Name, *Sym);
case SHN_XINDEX:
SecIndex = ELFObj->getExtendedSymbolTableIndex(Sym, Symtab, SymtabSHNDX);
break;
}
if (SecIndex >= Chunks.size() ||
(SecIndex != 0 && !Chunks[SecIndex]))
@@ -114,8 +120,6 @@ SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable,
error("unexpected binding");
case STB_GLOBAL:
case STB_WEAK:
if (Sym->isUndefined())
return new (Alloc) Undefined<ELFT>(Name, *Sym);
return new (Alloc) DefinedRegular<ELFT>(Name, *Sym, *Chunks[SecIndex]);
}
}

View File

@@ -40,9 +40,10 @@ public:
DefinedFirst = 0,
DefinedRegularKind = 0,
DefinedAbsoluteKind = 1,
DefinedLast = 1,
UndefinedKind = 2,
UndefinedSyntheticKind = 3
DefinedCommonKind = 2,
DefinedLast = 2,
UndefinedKind = 3,
UndefinedSyntheticKind = 4
};
Kind kind() const { return static_cast<Kind>(SymbolKind); }
@@ -134,6 +135,19 @@ public:
}
};
template <class ELFT> class DefinedCommon : public Defined<ELFT> {
typedef ELFSymbolBody<ELFT> Base;
typedef typename Base::Elf_Sym Elf_Sym;
public:
explicit DefinedCommon(StringRef N, const Elf_Sym &Sym)
: Defined<ELFT>(Base::DefinedCommonKind, N, Sym) {}
static bool classof(const SymbolBody *S) {
return S->kind() == Base::DefinedCommonKind;
}
};
// Regular defined symbols read from object file symbol tables.
template <class ELFT> class DefinedRegular : public Defined<ELFT> {
typedef Defined<ELFT> Base;

View File

@@ -310,6 +310,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
}
case SymbolBody::UndefinedKind:
assert(Body->isWeak() && "Should be defined by now");
case SymbolBody::DefinedCommonKind:
case SymbolBody::DefinedAbsoluteKind:
InputSym = &cast<ELFSymbolBody<ELFT>>(Body)->Sym;
break;

View File

@@ -31,6 +31,8 @@ zed3:
.globl abs
abs = 0x123
.comm common,4,4
// CHECK: Name: .text
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
@@ -93,6 +95,15 @@ abs = 0x123
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: common (34)
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 4
// CHECK-NEXT: Binding: Global (0x1)
// CHECK-NEXT: Type: Object (0x1)
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined (0x0)
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: zed
// CHECK-NEXT: Value: 0x1004
// CHECK-NEXT: Size: 0