[lld] r306304 - [COFF] Fix SECREL and SECTION relocations against common symbols
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 09:45:37 PDT 2017
Author: rnk
Date: Mon Jun 26 09:45:36 2017
New Revision: 306304
URL: http://llvm.org/viewvc/llvm-project?rev=306304&view=rev
Log:
[COFF] Fix SECREL and SECTION relocations against common symbols
Summary:
They do the obvious thing: provide the section index of .bss and the
offset of the symbol in .bss.
Reviewers: ruiu
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D34628
Added:
lld/trunk/test/COFF/secrel-common.s
Modified:
lld/trunk/COFF/Symbols.h
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=306304&r1=306303&r2=306304&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Mon Jun 26 09:45:36 2017
@@ -187,6 +187,8 @@ public:
}
uint64_t getRVA() { return Data->getRVA(); }
+ uint32_t getSecrel() { return Data->OutputSectionOff; }
+ uint16_t getSectionIndex();
private:
friend SymbolTable;
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=306304&r1=306303&r2=306304&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Jun 26 09:45:36 2017
@@ -215,6 +215,8 @@ uint32_t Defined::getSecrel() {
switch (kind()) {
case DefinedRegularKind:
return cast<DefinedRegular>(this)->getSecrel();
+ case DefinedCommonKind:
+ return cast<DefinedCommon>(this)->getSecrel();
case DefinedSyntheticKind:
return cast<DefinedSynthetic>(this)->getSecrel();
default:
@@ -235,6 +237,8 @@ uint16_t Defined::getSectionIndex() {
return D->getChunk()->getOutputSection()->SectionIndex;
if (isa<DefinedAbsolute>(this))
return DefinedAbsolute::OutputSectionIndex;
+ if (auto *D = dyn_cast<DefinedCommon>(this))
+ return D->getSectionIndex();
if (auto *D = dyn_cast<DefinedSynthetic>(this)) {
if (!D->getChunk())
return 0;
@@ -244,6 +248,10 @@ uint16_t Defined::getSectionIndex() {
toString(*this));
}
+uint16_t DefinedCommon::getSectionIndex() {
+ return Data->getOutputSection()->SectionIndex;
+}
+
bool Defined::isExecutable() {
const auto X = IMAGE_SCN_MEM_EXECUTE;
if (auto *D = dyn_cast<DefinedRegular>(this))
Added: lld/trunk/test/COFF/secrel-common.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/secrel-common.s?rev=306304&view=auto
==============================================================================
--- lld/trunk/test/COFF/secrel-common.s (added)
+++ lld/trunk/test/COFF/secrel-common.s Mon Jun 26 09:45:36 2017
@@ -0,0 +1,41 @@
+# RUN: llvm-mc %s -filetype=obj -triple=x86_64-windows-msvc -o %t.obj
+# RUN: lld-link -entry:main -nodefaultlib %t.obj -out:%t.exe
+# RUN: llvm-readobj %t.exe -sections -section-data | FileCheck %s
+
+# Section relocations against common symbols resolve to .bss.
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK: Number: 1
+# CHECK: Name: .bss (2E 62 73 73 00 00 00 00)
+# CHECK: VirtualSize: 0x4
+# CHECK: }
+# CHECK: Section {
+# CHECK: Number: 2
+# CHECK: Name: .rdata (2E 72 64 61 74 61 00 00)
+# CHECK: SectionData (
+# CHECK: 0000: 00000000 01000000 |........|
+# CHECK: )
+# CHECK: }
+# CHECK: Section {
+# CHECK: Number: 3
+# CHECK: Name: .text (2E 74 65 78 74 00 00 00)
+# CHECK: VirtualSize: 0x1
+# CHECK: SectionData (
+# CHECK: 0000: C3 |.|
+# CHECK: )
+# CHECK: }
+# CHECK-NOT: Section
+# CHECK: ]
+
+.text
+.global main
+main:
+ret
+
+.comm common_global,4,2
+
+.section .rdata,"dr"
+.secrel32 common_global
+.secidx common_global
+.short 0
More information about the llvm-commits
mailing list