Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -351,6 +351,8 @@ // between start of a function and '_gp' value and defined as absolute just // to simplify the code. if (AbsVal && RelE) { + if (Body.isLocal() || Body.getVisibility() == STV_HIDDEN) + return true; if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak()) return true; if (&Body == ElfSym::MipsGpDisp) Index: test/ELF/Inputs/symbol-absolute.s =================================================================== --- /dev/null +++ test/ELF/Inputs/symbol-absolute.s @@ -0,0 +1,3 @@ +.globl _BASE +.hidden _BASE +_BASE = 0 Index: test/ELF/linkerscript/symbol-absolute.s =================================================================== --- /dev/null +++ test/ELF/linkerscript/symbol-absolute.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "PROVIDE_HIDDEN(_BASE = 0);" > %t.script +# RUN: ld.lld -shared --gc-sections -o %t1 %t %t.script +# RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t1 | FileCheck %s +# CHECK: 0000000000000000 0 NOTYPE LOCAL HIDDEN ABS _BASE + +.text +.globl _start +_start: + lea _BASE(%rip),%rax Index: test/ELF/symbol-absolute.s =================================================================== --- /dev/null +++ test/ELF/symbol-absolute.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tinput1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux \ +# RUN: %S/Inputs/symbol-absolute.s -o %tinput2.o +# RUN: ld.lld -shared --gc-sections -o %t %tinput1.o %tinput2.o +# RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t | FileCheck %s +# CHECK: 0000000000000000 0 NOTYPE LOCAL HIDDEN ABS _BASE + +.text +.globl _start +_start: + lea _BASE(%rip),%rax