1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 09:57:18 +03:00
This commit is contained in:
Rui Ueyama 2021-03-01 22:04:42 +09:00
parent b31b6da35a
commit a3df45cb86
3 changed files with 19 additions and 42 deletions

View File

@ -439,6 +439,9 @@ void InputSection::scan_relocations() {
file->num_dynrel++; file->num_dynrel++;
}; };
if (sym.st_type == STT_GNU_IFUNC)
sym.flags |= NEEDS_PLT;
switch (rel.r_type) { switch (rel.r_type) {
case R_X86_64_NONE: case R_X86_64_NONE:
rel_types[i] = R_NONE; rel_types[i] = R_NONE;
@ -511,7 +514,7 @@ void InputSection::scan_relocations() {
rel_types[i] = R_GOTPCREL; rel_types[i] = R_GOTPCREL;
break; break;
case R_X86_64_PLT32: case R_X86_64_PLT32:
if (sym.is_imported() || sym.st_type == STT_GNU_IFUNC) if (sym.is_imported())
sym.flags |= NEEDS_PLT; sym.flags |= NEEDS_PLT;
rel_types[i] = R_PC; rel_types[i] = R_PC;
break; break;

1
mold.h
View File

@ -55,6 +55,7 @@ enum class BuildIdKind : u8 { NONE, HASH, UUID };
struct Config { struct Config {
BuildIdKind build_id = BuildIdKind::NONE; BuildIdKind build_id = BuildIdKind::NONE;
bool Bsymbolic = false;
bool allow_multiple_definition = false; bool allow_multiple_definition = false;
bool demangle = true; bool demangle = true;
bool discard_all = false; bool discard_all = false;

View File

@ -5,53 +5,26 @@ echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0) t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t mkdir -p $t
cat <<EOF | cc -o $t/a.o -c -x assembler - cat <<EOF | clang -o $t/a.o -c -xc -
.text #include <stdio.h>
.globl real_foobar
real_foobar:
lea msg(%rip), %rdi
xor %rax, %rax
call printf
xor %rax, %rax
ret
.globl resolve_foobar void foo() __attribute__((ifunc("resolve_foo")));
resolve_foobar:
pushq %rbp
movq %rsp, %rbp
leaq real_foobar(%rip), %rax
popq %rbp
ret
.globl foobar void hello() {
.type foobar, @gnu_indirect_function printf("Hello world\n");
.set foobar, resolve_foobar }
.globl main void *resolve_foo() {
main: return hello;
pushq %rbp }
movq %rsp, %rbp
call foobar@PLT
xor %rax, %rax
popq %rbp
ret
.data int main() {
msg: foo();
.string "Hello world\n" return 0;
}
EOF EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.o -static
../mold -static -o $t/exe /usr/lib/x86_64-linux-gnu/crt1.o \
/usr/lib/x86_64-linux-gnu/crti.o \
/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
$t/a.o \
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a \
/usr/lib/x86_64-linux-gnu/libc.a \
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
/usr/lib/x86_64-linux-gnu/crtn.o
$t/exe | grep -q 'Hello world' $t/exe | grep -q 'Hello world'
echo OK echo OK