From 0a5314fdb31a27403b6b6d9f2f6d6186a00f4192 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 18 Oct 2010 20:25:33 +0000 Subject: [PATCH] Relocate with .bss instead of using the symbol. Matches gas behavior. llvm-svn: 116741 --- llvm/lib/MC/ELFObjectWriter.cpp | 3 +++ llvm/test/MC/ELF/relocation-386.s | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 1e0d535251fe..b5943ec717b8 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -560,6 +560,9 @@ static bool ShouldRelocOnSymbol(const MCSymbolData &SD, const MCSectionELF &Sec2 = static_cast(F.getParent()->getSection()); + if (Section.getKind().isBSS()) + return false; + if (&Sec2 != &Section && (Kind == MCSymbolRefExpr::VK_PLT || Kind == MCSymbolRefExpr::VK_GOTPCREL || diff --git a/llvm/test/MC/ELF/relocation-386.s b/llvm/test/MC/ELF/relocation-386.s index 68dc13268dfc..a29db542a8e3 100644 --- a/llvm/test/MC/ELF/relocation-386.s +++ b/llvm/test/MC/ELF/relocation-386.s @@ -3,10 +3,23 @@ // Test that we produce the correct relocation types and that the relocation // to .Lfoo uses the symbol and not the section. +// Section 3 is bss +// CHECK: # Section 3 +// CHECK-NEXT: (('sh_name', 13) # '.bss' // CHECK: # Symbol 1 // CHECK-NEXT: (('st_name', 5) # '.Lfoo' +// Symbol 6 is section 3 +// CHECK: # Symbol 6 +// CHECK-NEXT: (('st_name', 0) # '' +// CHECK-NEXT: ('st_value', 0) +// CHECK-NEXT: ('st_size', 0) +// CHECK-NEXT: ('st_bind', 0) +// CHECK-NEXT: ('st_type', 3) +// CHECK-NEXT: ('st_other', 0) +// CHECK-NEXT: ('st_shndx', 3) + // CHECK: # Relocation 0 // CHECK-NEXT: (('r_offset', 2) // CHECK-NEXT: ('r_sym', 1) @@ -21,6 +34,13 @@ // CHECK-NEXT: (('r_offset', // CHECK-NEXT: ('r_sym', // CHECK-NEXT: ('r_type', 10) +// CHECK-NEXT: ), + +// Relocation 3 (bar3@GOTOFF) is done symbol 6 (bss) +// CHECK-NEXT: # Relocation 3 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 6 +// CHECK-NEXT: ('r_type', // CHECK-NEXT: ), .text @@ -31,6 +51,11 @@ bar: bar2: calll bar2@PLT addl $_GLOBAL_OFFSET_TABLE_, %ebx + movb bar3@GOTOFF(%ebx), %al + + .type bar3,@object + .local bar3 + .comm bar3,1,1 .section .rodata.str1.16,"aMS",@progbits,1 .Lfoo: