[lld] r248054 - [elf2] Relocate against common symbols.
Michael J. Spencer via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 18 15:13:26 PDT 2015
Author: mspencer
Date: Fri Sep 18 17:13:25 2015
New Revision: 248054
URL: http://llvm.org/viewvc/llvm-project?rev=248054&view=rev
Log:
[elf2] Relocate against common symbols.
Added:
lld/trunk/test/elf2/relocation-common.s
Modified:
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=248054&r1=248053&r2=248054&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Fri Sep 18 17:13:25 2015
@@ -24,6 +24,7 @@ class Chunk;
class InputFile;
class SymbolBody;
template <class ELFT> class ObjectFile;
+template <class ELFT> class OutputSection;
// A real symbol object, SymbolBody, is usually accessed indirectly
// through a Symbol. There's always one Symbol for each symbol name.
@@ -180,6 +181,8 @@ public:
// The maximum alignment we have seen for this symbol.
uintX_t MaxAlignment;
+
+ OutputSection<ELFT> *OutputSec = nullptr;
};
// Regular defined symbols read from object file symbol tables.
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248054&r1=248053&r2=248054&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Sep 18 17:13:25 2015
@@ -738,8 +738,11 @@ void OutputSection<ELFT>::relocate(
case SymbolBody::DefinedAbsoluteKind:
SymVA = cast<DefinedAbsolute<ELFT>>(Body)->Sym.st_value;
break;
- case SymbolBody::DefinedCommonKind:
- continue;
+ case SymbolBody::DefinedCommonKind: {
+ auto *DC = cast<DefinedCommon<ELFT>>(Body);
+ SymVA = DC->OutputSec->getVA() + DC->OffsetInBSS;
+ break;
+ }
case SymbolBody::SharedKind:
if (!relocNeedsGOT(Type))
continue;
@@ -1063,6 +1066,7 @@ template <class ELFT> void Writer<ELFT>:
uintX_t Align = C->MaxAlignment;
Off = RoundUpToAlignment(Off, Align);
C->OffsetInBSS = Off;
+ C->OutputSec = BSSSec;
Off += Sym.st_size;
}
Added: lld/trunk/test/elf2/relocation-common.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-common.s?rev=248054&view=auto
==============================================================================
--- lld/trunk/test/elf2/relocation-common.s (added)
+++ lld/trunk/test/elf2/relocation-common.s Fri Sep 18 17:13:25 2015
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: lld -flavor gnu2 %t -o %tout
+// RUN: llvm-objdump -t -d %tout | FileCheck %s
+// REQUIRES: x86
+
+.global _start
+_start:
+ movl $1, sym1(%rip)
+
+.global sym1
+.comm sym1,4,4
+
+// CHECK: 11000: {{.*}} movl $1, 4086(%rip)
+// CHECK: 0000000000012000 g .bss 00000004 sym1
More information about the llvm-commits
mailing list