llvm-project/lld/test/ELF/textrel.s
Ali Tamur 63830b2794 Introduce a flag to warn when ifunc symbols are used with text relocations.
Summary:
This patch adds a new flag, --warn-ifunc-textrel, to work around a glibc bug. When a code with ifunc symbols is used to produce an object file with text relocations, lld always succeeds. However, if that object file is linked using an old version of glibc, the resultant binary just crashes with segmentation fault when it is run (The bug is going to be corrected as of glibc 2.19).

Since there is no way to tell beforehand what library the object file will be linked against in the future, there does not seem to be a fool-proof way for lld to give an error only in cases where the binary will crash. So, with this change (dated 2018-09-25), lld starts to give a warning, contingent on a new command line flag that does not have a gnu counter part. The default value for --warn-ifunc-textrel is false, so lld behaviour will not change unless the user explicitly asks lld to give a warning. Users that link with a glibc library with version 2.19 or newer, or does not use ifunc symbols, or does not generate object files with text relocations do not need to take any action. Other users may consider to start passing warn-ifunc-textrel to lld to get early warnings.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: grimar, MaskRay, markj, emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D52430

llvm-svn: 343628
2018-10-02 20:30:22 +00:00

41 lines
1.2 KiB
ArmAsm

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux-gnu %s -o %t.o
# Without --warn-text-ifunc, lld should run fine:
# RUN: ld.lld -z notext %t.o -o %t2
# With --warn-text-ifunc, lld should run with warnings:
# RUN: ld.lld --warn-ifunc-textrel -z notext %t.o -o /dev/null 2>&1 | FileCheck %s
# CHECK: using ifunc symbols when text relocations are allowed may produce
# CHECK-SAME: a binary that will segfault, if the object file is linked with
# CHECK-SAME: old version of glibc (glibc 2.28 and earlier). If this applies to
# CHECK-SAME: you, consider recompiling the object files without -fPIC and
# CHECK-SAME: without -Wl,-z,notext option. Use -no-warn-ifunc-textrel to
# CHECK-SAME: turn off this warning.
# CHECK: >>> defined in {{.*}}
# CHECK: >>> referenced by {{.*}}:(.text+0x8)
# Without text relocations, lld should run fine:
# RUN: ld.lld --fatal-warnings %t.o -o /dev/null
.text
.globl a_func_impl
a_func_impl:
nop
.globl selector
.type selector,@function
selector:
movl $a_func_impl, %eax
retq
.globl a_func
.type a_func,@gnu_indirect_function
.set a_func, selector
.globl _start
.type _start,@function
main:
callq a_func
retq