Skip to content

Commit 55e69ec

Browse files
committed
[ELF] Remove -Wl,-z,notext hint
The hint does not pull its weight: * adding -Wl,-z,notext often won't work (relocation types other than `symbolRel`, e.g. `R_AARCH64_LDST32_ABS_LO12_NC`) * for pure (no assembly) C/C++ projects, the "-fPIC" hint is sufficient
1 parent 81a6eab commit 55e69ec

31 files changed

+39
-58
lines changed

lld/ELF/Relocations.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,19 +1095,10 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type,
10951095
}
10961096

10971097
if (config->isPic) {
1098-
if (!canWrite && !isRelExpr(expr))
1099-
errorOrWarn(
1100-
"can't create dynamic relocation " + toString(type) + " against " +
1101-
(sym.getName().empty() ? "local symbol"
1102-
: "symbol: " + toString(sym)) +
1103-
" in readonly segment; recompile object files with -fPIC "
1104-
"or pass '-Wl,-z,notext' to allow text relocations in the output" +
1105-
getLocation(sec, sym, offset));
1106-
else
1107-
errorOrWarn(
1108-
"relocation " + toString(type) + " cannot be used against " +
1109-
(sym.getName().empty() ? "local symbol" : "symbol " + toString(sym)) +
1110-
"; recompile with -fPIC" + getLocation(sec, sym, offset));
1098+
errorOrWarn("relocation " + toString(type) + " cannot be used against " +
1099+
(sym.getName().empty() ? "local symbol"
1100+
: "symbol '" + toString(sym) + "'") +
1101+
"; recompile with -fPIC" + getLocation(sec, sym, offset));
11111102
return;
11121103
}
11131104

lld/test/ELF/aarch64-abs32-dyn.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Test we don't create R_AARCH64_RELATIVE.
66

7-
# CHECK: error: relocation R_AARCH64_ABS32 cannot be used against symbol hidden; recompile with -fPIC
7+
# CHECK: error: relocation R_AARCH64_ABS32 cannot be used against symbol 'hidden'; recompile with -fPIC
88

99
.globl hidden
1010
.hidden hidden

lld/test/ELF/aarch64-fpic-abs16.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: relocation R_AARCH64_ABS16 cannot be used against symbol foo; recompile with -fPIC
4+
// CHECK: relocation R_AARCH64_ABS16 cannot be used against symbol 'foo'; recompile with -fPIC
55
// CHECK-NEXT: >>> defined in {{.*}}.o
66
// CHECK-NEXT: >>> referenced by {{.*}}.o:(.data+0x0)
77

lld/test/ELF/aarch64-fpic-add_abs_lo12_nc.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
4+
// CHECK: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'dat'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}.o
66
// CHECK: >>> referenced by {{.*}}.o:(.text+0x0)
77

lld/test/ELF/aarch64-fpic-adr_prel_lo21.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: relocation R_AARCH64_ADR_PREL_LO21 cannot be used against symbol dat; recompile with -fPIC
4+
// CHECK: error: relocation R_AARCH64_ADR_PREL_LO21 cannot be used against symbol 'dat'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}.o
66
// CHECK: >>> referenced by {{.*}}.o:(.text+0x0)
77

lld/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol dat; recompile with -fPIC
4+
// CHECK: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'dat'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}.o
66
// CHECK: >>> referenced by {{.*}}.o:(.text+0x0)
7-
// CHECK: relocation R_AARCH64_ADR_PREL_PG_HI21_NC cannot be used against symbol dat; recompile with -fPIC
7+
// CHECK: error: relocation R_AARCH64_ADR_PREL_PG_HI21_NC cannot be used against symbol 'dat'; recompile with -fPIC
88

99
adrp x0, dat
1010
adrp x0, :pg_hi21_nc:dat

lld/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
4+
// CHECK: error: relocation R_AARCH64_LDST32_ABS_LO12_NC cannot be used against symbol 'dat'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}.o
66
// CHECK: >>> referenced by {{.*}}.o:(.text+0x0)
77

lld/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
4+
// CHECK: error: relocation R_AARCH64_LDST64_ABS_LO12_NC cannot be used against symbol 'dat'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}.o
66
// CHECK: >>> referenced by {{.*}}.o:(.text+0x0)
77

lld/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
4+
// CHECK: error: relocation R_AARCH64_LDST8_ABS_LO12_NC cannot be used against symbol 'dat'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}.o
66
// CHECK: >>> referenced by {{.*}}.o:(.text+0x0)
77

lld/test/ELF/aarch64-fpic-prel16.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: aarch64
22
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
33
// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s
4-
// CHECK: R_AARCH64_PREL16 cannot be used against symbol foo; recompile with -fPIC
4+
// CHECK: R_AARCH64_PREL16 cannot be used against symbol 'foo'; recompile with -fPIC
55
// CHECK: >>> defined in {{.*}}
66
// CHECK: >>> referenced by {{.*}}:(.data+0x0)
77

0 commit comments

Comments
 (0)