Skip to content

Commit 382df1c

Browse files
committed
Revert "Reland D64327 [MC][ELF] Allow STT_SECTION referencing SHF_MERGE on REL targets"
This reverts commit b497665. Spent some time trying to reproduce this locally, reverting in a desparate attempt to fix the sanitizer buildbot: - http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/28828 I don't know exactly why or how this patch breaks the bots, but it seems pretty concrete that it's the culprit.
1 parent ac3e720 commit 382df1c

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,8 @@ function(add_link_opts target_name)
222222
# Pass -O3 to the linker. This enabled different optimizations on different
223223
# linkers.
224224
if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS|AIX" OR WIN32))
225-
# Before binutils 2.34, gold -O2 and above did not correctly handle R_386_GOTOFF to
226-
# SHF_MERGE|SHF_STRINGS sections: https://sourceware.org/bugzilla/show_bug.cgi?id=16794
227-
if(LLVM_LINKER_IS_GOLD)
228-
set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-O1")
229-
else()
230-
set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-O3")
231-
endif()
225+
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
226+
LINK_FLAGS " -Wl,-O3")
232227
endif()
233228

234229
if(LLVM_LINKER_IS_GOLD)

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,11 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
13931393
if (Flags & ELF::SHF_MERGE) {
13941394
if (C != 0)
13951395
return true;
1396+
1397+
// It looks like gold has a bug (http://sourceware.org/PR16794) and can
1398+
// only handle section relocations to mergeable sections if using RELA.
1399+
if (!hasRelocationAddend())
1400+
return true;
13961401
}
13971402

13981403
// Most TLS relocations use a got, so they need the symbol. Even those that

llvm/test/MC/ELF/basic-elf-32.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ main: # @main
4646

4747
// CHECK: Relocations [
4848
// CHECK: Section {{.*}} .rel.text {
49-
// CHECK: 0x6 R_386_32 .rodata.str1.1 0x0
49+
// CHECK: 0x6 R_386_32 .L.str1
5050
// CHECK: 0xB R_386_PC32 puts
51-
// CHECK: 0x12 R_386_32 .rodata.str1.1 0x0
51+
// CHECK: 0x12 R_386_32 .L.str2
5252
// CHECK: 0x17 R_386_PC32 puts
5353
// CHECK: }
5454
// CHECK: ]

llvm/test/MC/ELF/compression.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
// In x86 32 bit named symbols are used for temporary symbols in merge
4040
// sections, so make sure we handle symbols inside compressed sections
41-
// 386-SYMBOLS-GNU: Name: .zdebug_str
41+
// 386-SYMBOLS-GNU: Name: .Linfo_string0
4242
// 386-SYMBOLS-GNU-NOT: }
4343
// 386-SYMBOLS-GNU: Section: .zdebug_str
4444

@@ -73,7 +73,7 @@
7373
// ZLIB-STYLE-FLAGS32-NEXT: AddressAlignment: 4
7474
// ZLIB-STYLE-FLAGS64-NEXT: AddressAlignment: 8
7575

76-
// 386-SYMBOLS-ZLIB: Name: .debug_str
76+
// 386-SYMBOLS-ZLIB: Name: .Linfo_string0
7777
// 386-SYMBOLS-ZLIB-NOT: }
7878
// 386-SYMBOLS-ZLIB: Section: .debug_str
7979

llvm/test/MC/ELF/relocation-386.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// I386: Format: elf32-i386
99
// CHECK: Relocations [
1010
// CHECK-NEXT: Section {{.*}} .rel.text {
11-
// CHECK-NEXT: 0x2 R_386_GOTOFF .rodata.str1.16 0x0
11+
// CHECK-NEXT: 0x2 R_386_GOTOFF .Lfoo 0x0
1212
// CHECK-NEXT: 0x{{[^ ]+}} R_386_PLT32 bar2 0x0
1313
// CHECK-NEXT: 0x{{[^ ]+}} R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0
1414
// Relocation 3 (bar3@GOTOFF) is done with symbol 7 (bss)

llvm/test/MC/Mips/elf-relsym.s

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
// CHECK: Symbols [
66
// CHECK: Symbol {
7-
// CHECK: Name: .rodata.cst8
7+
// CHECK: Name: $.str
88
// CHECK: }
99
// CHECK: Symbol {
10-
// CHECK: Name: .rodata.str1.1
10+
// CHECK: Name: $.str1
11+
// CHECK: }
12+
// CHECK: Symbol {
13+
// CHECK: Name: $CPI0_0
14+
// CHECK: }
15+
// CHECK: Symbol {
16+
// CHECK: Name: $CPI0_1
1117
// CHECK: }
1218
// CHECK: ]
1319

llvm/test/MC/Mips/xgot.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// CHECK: 0x1C R_MIPS_GOT_LO16 ext_1
1111
// CHECK: 0x24 R_MIPS_CALL_HI16 printf
1212
// CHECK: 0x30 R_MIPS_CALL_LO16 printf
13-
// CHECK: 0x2C R_MIPS_GOT16 .rodata.str1.1 0x0
14-
// CHECK: 0x38 R_MIPS_LO16 .rodata.str1.1 0x0
13+
// CHECK: 0x2C R_MIPS_GOT16 $.str
14+
// CHECK: 0x38 R_MIPS_LO16 $.str
1515
// CHECK: ]
1616

1717
.text

0 commit comments

Comments
 (0)