From e459f72ee0e24a26c9625bc7485f050ef5753ddc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 27 Mar 2014 00:28:24 +0000 Subject: [PATCH] Correctly propagates st_size. This also finally removes a bogus call to AliasedSymbol. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204883 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 13 ++++++------- test/MC/ELF/offset.s | 11 ++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 7c2135b2487..277716c89b4 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -609,9 +609,6 @@ static const MCSymbol *getBaseSymbol(const MCAsmLayout &Layout, void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD, const MCAsmLayout &Layout) { MCSymbolData &OrigData = *MSD.SymbolData; - MCSymbolData &Data = - Layout.getAssembler().getSymbolData(OrigData.getSymbol().AliasedSymbol()); - const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol()); // This has to be in sync with when computeSymbolTable uses SHN_ABS or @@ -621,9 +618,10 @@ void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD, // Binding and Type share the same byte as upper and lower nibbles uint8_t Binding = MCELF::GetBinding(OrigData); uint8_t Type = MCELF::GetType(OrigData); + MCSymbolData *BaseSD = nullptr; if (Base) { - MCSymbolData BaseSD = Layout.getAssembler().getSymbolData(*Base); - Type = mergeTypeForSet(Type, MCELF::GetType(BaseSD)); + BaseSD = &Layout.getAssembler().getSymbolData(*Base); + Type = mergeTypeForSet(Type, MCELF::GetType(*BaseSD)); } if (OrigData.getFlags() & ELF_Other_ThumbFunc) Type = ELF::STT_FUNC; @@ -640,9 +638,10 @@ void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD, Value |= 1; uint64_t Size = 0; - assert(!(Data.isCommon() && !Data.isExternal())); + const MCExpr *ESize = OrigData.getSize(); + if (!ESize && Base) + ESize = BaseSD->getSize(); - const MCExpr *ESize = Data.getSize(); if (ESize) { int64_t Res; if (!ESize->EvaluateAsAbsolute(Res, Layout)) diff --git a/test/MC/ELF/offset.s b/test/MC/ELF/offset.s index bc4252c1a78..a412619143f 100644 --- a/test/MC/ELF/offset.s +++ b/test/MC/ELF/offset.s @@ -5,6 +5,7 @@ .data .globl sym_a + .size sym_a, 42 .byte 42 .type sym_a, @object sym_a: @@ -12,7 +13,7 @@ sym_a: // CHECK: Symbol { // CHECK: Name: sym_a // CHECK-NEXT: Value: 0x1 -// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Size: 42 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: 0 @@ -27,7 +28,7 @@ sym_c = sym_a // CHECK: Symbol { // CHECK: Name: sym_c // CHECK-NEXT: Value: 0x1 -// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Size: 42 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: 0 @@ -39,7 +40,7 @@ sym_d = sym_a + 1 // CHECK: Symbol { // CHECK: Name: sym_d // CHECK-NEXT: Value: 0x2 -// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Size: 42 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: 0 @@ -51,7 +52,7 @@ sym_e = sym_a + (sym_b - sym_a) * 3 // CHECK: Symbol { // CHECK: Name: sym_e // CHECK-NEXT: Value: 0xD -// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Size: 42 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: 0 @@ -64,7 +65,7 @@ sym_f = sym_a + (1 - 1) // CHECK: Symbol { // CHECK: Name: sym_f // CHECK-NEXT: Value: 0x1 -// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Size: 42 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: 0