mirror of
https://github.com/rui314/mold.git
synced 2024-12-24 17:01:50 +03:00
temporary
This commit is contained in:
parent
48178b2a73
commit
cf22ce3f9a
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
*.o
|
||||
*~
|
||||
/mold
|
||||
/test/Output
|
||||
/test/tmp
|
||||
options.inc
|
||||
core
|
||||
|
2
Makefile
2
Makefile
@ -26,7 +26,7 @@ intel_tbb:
|
||||
$(MAKE) -C oneTBB
|
||||
|
||||
test: mold
|
||||
./llvm-project/build/bin/llvm-lit test
|
||||
(cd test; for i in *.sh; do ./$$i; done)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ mold
|
||||
|
3
elf.cc
3
elf.cc
@ -9,7 +9,8 @@ ElfFile::ElfFile(MemoryMappedFile mb) : mb(mb), ehdr((ElfEhdr &)*mb.data) {
|
||||
u8 *begin = mb.data + ehdr.e_shoff;
|
||||
u8 *end = begin + ehdr.e_shnum * sizeof(ElfShdr);
|
||||
if (mb.data + mb.size < end)
|
||||
error(mb.name + ": e_shoff or e_shnum corrupted");
|
||||
error(mb.name + ": e_shoff or e_shnum corrupted: " +
|
||||
std::to_string(mb.size) + " " + std::to_string(ehdr.e_shnum));
|
||||
sections = {(ElfShdr *)begin, (ElfShdr *)end};
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ bool is_c_identifier(std::string_view name) {
|
||||
ObjectFile *ObjectFile::create_internal_file() {
|
||||
// Create a dummy object file.
|
||||
constexpr int bufsz = 256;
|
||||
u8 *buf = new u8[bufsz];
|
||||
u8 *buf = (u8 *)calloc(1, bufsz);
|
||||
memcpy(buf, "\177ELF", 4);
|
||||
MemoryMappedFile *mb = new MemoryMappedFile("<internal>", buf, bufsz);
|
||||
auto *obj = new ObjectFile(*mb, "");
|
||||
|
@ -1,20 +0,0 @@
|
||||
// RUN: cc -o %t1.o -c %s
|
||||
// RUN: echo 'int fn1() { return 42; }' | cc -o %t2.so -shared -fPIC -Wl,-soname,libfoo.so -xc -
|
||||
// RUN: echo 'int fn2() { return 42; }' | cc -o %t3.so -shared -fPIC -Wl,-soname,libbar.so -xc -
|
||||
|
||||
// RUN: mold -o %t.exe %t1.o %t2.so %t3.so
|
||||
// RUN: readelf --dynamic %t.exe | FileCheck --check-prefix=CHECK1 %s
|
||||
// RUN: mold -o %t.exe %t1.o --as-needed --no-as-needed %t2.so %t3.so
|
||||
// RUN: readelf --dynamic %t.exe | FileCheck --check-prefix=CHECK1 %s
|
||||
// CHECK1: 0x0000000000000001 (NEEDED) Shared library: [libfoo.so]
|
||||
// CHECK1: 0x0000000000000001 (NEEDED) Shared library: [libbar.so]
|
||||
|
||||
// RUN: mold -o %t.exe %t1.o --as-needed %t2.so %t3.so
|
||||
// RUN: readelf --dynamic %t.exe | FileCheck --check-prefix=CHECK2 %s
|
||||
// CHECK2: 0x0000000000000001 (NEEDED) Shared library: [libfoo.so]
|
||||
// CHECK2-NOT: 0x0000000000000001 (NEEDED) Shared library: [libbar.so]
|
||||
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
call fn1@PLT
|
34
test/as-needed.sh
Executable file
34
test/as-needed.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
call fn1@PLT
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -o $t/b.so -shared -fPIC -Wl,-soname,libfoo.so -xc -
|
||||
int fn1() { return 42; }
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -o $t/c.so -shared -fPIC -Wl,-soname,libbar.so -xc -
|
||||
int fn2() { return 42; }
|
||||
EOF
|
||||
|
||||
../mold -o $t/exe $t/a.o $t/b.so $t/c.so > /dev/null
|
||||
|
||||
readelf --dynamic $t/exe > $t/readelf
|
||||
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
|
||||
fgrep -q 'Shared library: [libbar.so]' $t/readelf
|
||||
|
||||
../mold -o $t/exe $t/a.o --as-needed $t/b.so $t/c.so > /dev/null
|
||||
|
||||
readelf --dynamic $t/exe > $t/readelf
|
||||
fgrep -q 'Shared library: [libfoo.so]' $t/readelf
|
||||
! fgrep -q 'Shared library: [libbar.so]' $t/readelf
|
||||
|
||||
echo ' OK'
|
13
test/basic.sh
Executable file
13
test/basic.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
echo '.globl _start; _start: jmp loop' | cc -o $t/a.o -c -x assembler -
|
||||
echo '.globl loop; loop: jmp loop' | cc -o $t/b.o -c -x assembler -
|
||||
../mold -static -o $t/exe $t/a.o $t/b.o > /dev/null
|
||||
objdump -d $t/exe > /dev/null
|
||||
file $t/exe | grep -q ELF
|
||||
|
||||
echo ' OK'
|
@ -1,5 +0,0 @@
|
||||
RUN: echo '.globl _start; _start: jmp loop' | cc -o %t1.o -c -x assembler -
|
||||
RUN: echo '.globl loop; loop: jmp loop' | cc -o %t2.o -c -x assembler -
|
||||
RUN: mold -static -o %t %t2.o %t1.o
|
||||
RUN: objdump -d %t
|
||||
RUN: file %t | grep ELF
|
@ -1,24 +0,0 @@
|
||||
// RUN: cc -o %t1.o -c %s
|
||||
// RUN: echo '.globl foo, bar; .data; foo: bar: .long 42' | cc -o %t2.o -c -x assembler -
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t1.o %t2.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep '42 42 1'
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int foo;
|
||||
extern int bar;
|
||||
|
||||
int main() {
|
||||
printf("%d %d %d\n", foo, bar, &foo == &bar);
|
||||
return 0;
|
||||
}
|
41
test/copyrel.sh
Executable file
41
test/copyrel.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -xc -
|
||||
#include <stdio.h>
|
||||
|
||||
extern int foo;
|
||||
extern int bar;
|
||||
|
||||
int main() {
|
||||
printf("%d %d %d\n", foo, bar, &foo == &bar);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -o $t/b.o -c -x assembler -
|
||||
.globl foo, bar
|
||||
.data;
|
||||
foo:
|
||||
bar:
|
||||
.long 42
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o $t/b.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q '42 42 1'
|
||||
|
||||
echo ' OK'
|
@ -1,8 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: not mold -o %t.exe %t.o %t.o 2> %t.log
|
||||
// RUN: grep 'duplicate symbol: .*\.o: .*\.o: main' %t.log
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
nop
|
17
test/duplicate-error.sh
Executable file
17
test/duplicate-error.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
nop
|
||||
EOF
|
||||
|
||||
! ../mold -o $t/exe $t/a.o $t/a.o 2> $t/log
|
||||
grep -q 'duplicate symbol: .*\.o: .*\.o: main' $t/log
|
||||
|
||||
echo ' OK'
|
@ -1,52 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: /home/ruiu/mold/test/Output/hello-dynamic.s.tmp.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
|
||||
|
||||
// RUN: readelf --dynamic %t.exe | FileCheck %s
|
||||
// CHECK: Dynamic section at offset 0x2048 contains 26 entries:
|
||||
// CHECK: Tag Type Name/Value
|
||||
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
|
||||
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
|
||||
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
|
||||
// CHECK: 0x0000000000000007 (RELA) 0x2001c8
|
||||
// CHECK: 0x0000000000000008 (RELASZ) 24 (bytes)
|
||||
// CHECK: 0x0000000000000009 (RELAENT) 24 (bytes)
|
||||
// CHECK: 0x0000000000000017 (JMPREL) 0x2001b0
|
||||
// CHECK: 0x0000000000000002 (PLTRELSZ) 24 (bytes)
|
||||
// CHECK: 0x0000000000000003 (PLTGOT) 0x202028
|
||||
// CHECK: 0x0000000000000014 (PLTREL) RELA
|
||||
// CHECK: 0x0000000000000006 (SYMTAB) 0x2001e0
|
||||
// CHECK: 0x000000000000000b (SYMENT) 24 (bytes)
|
||||
// CHECK: 0x0000000000000005 (STRTAB) 0x200228
|
||||
// CHECK: 0x000000000000000a (STRSZ) 83 (bytes)
|
||||
// CHECK: 0x0000000000000004 (HASH) 0x20027c
|
||||
// CHECK: 0x0000000000000019 (INIT_ARRAY) 0x202210
|
||||
// CHECK: 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
|
||||
// CHECK: 0x000000000000001a (FINI_ARRAY) 0x202208
|
||||
// CHECK: 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
|
||||
// CHECK: 0x000000006ffffff0 (VERSYM) 0x20029c
|
||||
// CHECK: 0x000000006ffffffe (VERNEED) 0x2002a8
|
||||
// CHECK: 0x000000006fffffff (VERNEEDNUM) 1
|
||||
// CHECK: 0x0000000000000015 (DEBUG) 0x0
|
||||
// CHECK: 0x000000000000000c (INIT) 0x201030
|
||||
// CHECK: 0x000000000000000d (FINI) 0x201020
|
||||
// CHECK: 0x0000000000000000 (NULL) 0x0
|
||||
|
||||
// RUN: readelf --symbols --use-dynamic %t.exe | FileCheck --check-prefix=DYNAMIC %s
|
||||
|
||||
// DYNAMIC: Symbol table for image:
|
||||
// DYNAMIC: Num Buc: Value Size Type Bind Vis Ndx Name
|
||||
// DYNAMIC: 1 1: 0000000000000000 483 FUNC GLOBAL DEFAULT UND __libc_start_main
|
||||
// DYNAMIC: 2 2: 0000000000000000 204 FUNC GLOBAL DEFAULT UND printf
|
||||
|
||||
.globl main
|
||||
main:
|
59
test/dynamic.sh
Executable file
59
test/dynamic.sh
Executable file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
echo '.globl main; main:' | cc -o $t/a.o -c -x assembler -
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 > /dev/null
|
||||
|
||||
readelf --dynamic $t/exe | grep -q "
|
||||
Dynamic section at offset 0x2048 contains 26 entries:
|
||||
Tag Type Name/Value
|
||||
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
|
||||
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
|
||||
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
|
||||
0x0000000000000007 (RELA) 0x2001c8
|
||||
0x0000000000000008 (RELASZ) 24 (bytes)
|
||||
0x0000000000000009 (RELAENT) 24 (bytes)
|
||||
0x0000000000000017 (JMPREL) 0x2001b0
|
||||
0x0000000000000002 (PLTRELSZ) 24 (bytes)
|
||||
0x0000000000000003 (PLTGOT) 0x202028
|
||||
0x0000000000000014 (PLTREL) RELA
|
||||
0x0000000000000006 (SYMTAB) 0x2001e0
|
||||
0x000000000000000b (SYMENT) 24 (bytes)
|
||||
0x0000000000000005 (STRTAB) 0x200228
|
||||
0x000000000000000a (STRSZ) 83 (bytes)
|
||||
0x0000000000000004 (HASH) 0x20027c
|
||||
0x0000000000000019 (INIT_ARRAY) 0x202210
|
||||
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
|
||||
0x000000000000001a (FINI_ARRAY) 0x202208
|
||||
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
|
||||
0x000000006ffffff0 (VERSYM) 0x20029c
|
||||
0x000000006ffffffe (VERNEED) 0x2002a8
|
||||
0x000000006fffffff (VERNEEDNUM) 1
|
||||
0x0000000000000015 (DEBUG) 0x0
|
||||
0x000000000000000c (INIT) 0x201030
|
||||
0x000000000000000d (FINI) 0x201020
|
||||
0x0000000000000000 (NULL) 0x0
|
||||
"
|
||||
|
||||
readelf --symbols --use-dynamic $t/exe | grep -q "
|
||||
Symbol table for image:
|
||||
Num Buc: Value Size Type Bind Vis Ndx Name
|
||||
1 1: 0000000000000000 483 FUNC GLOBAL DEFAULT UND __libc_start_main
|
||||
2 2: 0000000000000000 204 FUNC GLOBAL DEFAULT UND printf
|
||||
"
|
||||
|
||||
echo ' OK'
|
@ -1,38 +0,0 @@
|
||||
// RUN: cc -o %t1.o -c %s
|
||||
// RUN: cc -shared -fPIC -o %t2.so -xc - < /dev/null
|
||||
// RUN: mold -o %t.exe %t1.o %t2.so --export-dynamic
|
||||
|
||||
// RUN: readelf --dyn-syms %t.exe | FileCheck %s
|
||||
// CHECK: Symbol table '.dynsym' contains 19 entries:
|
||||
// CHECK: Num: Value Size Type Bind Vis Ndx Name
|
||||
// CHECK: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
||||
// CHECK: 1: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 6 foo
|
||||
// CHECK: 2: 0000000000201011 0 NOTYPE GLOBAL DEFAULT 6 bar
|
||||
// CHECK: 3: 0000000000201012 0 NOTYPE GLOBAL DEFAULT 6 _start
|
||||
// CHECK: 4: 0000000000200000 0 NOTYPE GLOBAL DEFAULT ABS __ehdr_start
|
||||
// CHECK: 5: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __rela_iplt_start
|
||||
// CHECK: 6: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __rela_iplt_end
|
||||
// CHECK: 7: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __init_array_start
|
||||
// CHECK: 8: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __init_array_end
|
||||
// CHECK: 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __fini_array_start
|
||||
// CHECK: 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __fini_array_end
|
||||
// CHECK: 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __preinit_array_start
|
||||
// CHECK: 12: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __preinit_array_end
|
||||
// CHECK: 13: 0000000000202018 0 NOTYPE GLOBAL DEFAULT ABS _DYNAMIC
|
||||
// CHECK: 14: 0000000000202000 0 NOTYPE GLOBAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_
|
||||
// CHECK: 15: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
|
||||
// CHECK: 16: 0000000000202178 0 NOTYPE GLOBAL DEFAULT ABS _end
|
||||
// CHECK: 17: 0000000000201013 0 NOTYPE GLOBAL DEFAULT ABS _etext
|
||||
// CHECK: 18: 0000000000202178 0 NOTYPE GLOBAL DEFAULT ABS _edata
|
||||
|
||||
.text
|
||||
.globl foo
|
||||
.hidden foo
|
||||
foo:
|
||||
nop
|
||||
.globl bar
|
||||
bar:
|
||||
nop
|
||||
.globl _start
|
||||
_start:
|
||||
nop
|
48
test/export-dynamic.sh
Executable file
48
test/export-dynamic.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl foo
|
||||
.hidden foo
|
||||
foo:
|
||||
nop
|
||||
.globl bar
|
||||
bar:
|
||||
nop
|
||||
.globl _start
|
||||
_start:
|
||||
nop
|
||||
EOF
|
||||
|
||||
cc -shared -fPIC -o $t/b.so -xc /dev/null
|
||||
../mold -o $t/exe $t/a.o $t/b.so --export-dynamic > /dev/null
|
||||
|
||||
readelf --dyn-syms $t/exe | grep -q "
|
||||
Symbol table '.dynsym' contains 19 entries:
|
||||
Num: Value Size Type Bind Vis Ndx Name
|
||||
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
||||
1: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 6 foo
|
||||
2: 0000000000201011 0 NOTYPE GLOBAL DEFAULT 6 bar
|
||||
3: 0000000000201012 0 NOTYPE GLOBAL DEFAULT 6 _start
|
||||
4: 0000000000200000 0 NOTYPE GLOBAL DEFAULT ABS __ehdr_start
|
||||
5: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __rela_iplt_start
|
||||
6: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __rela_iplt_end
|
||||
7: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __init_array_start
|
||||
8: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __init_array_end
|
||||
9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __fini_array_start
|
||||
10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __fini_array_end
|
||||
11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __preinit_array_start
|
||||
12: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __preinit_array_end
|
||||
13: 0000000000202018 0 NOTYPE GLOBAL DEFAULT ABS _DYNAMIC
|
||||
14: 0000000000202000 0 NOTYPE GLOBAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_
|
||||
15: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
|
||||
16: 0000000000202178 0 NOTYPE GLOBAL DEFAULT ABS _end
|
||||
17: 0000000000201013 0 NOTYPE GLOBAL DEFAULT ABS _etext
|
||||
18: 0000000000202178 0 NOTYPE GLOBAL DEFAULT ABS _edata
|
||||
"
|
||||
|
||||
echo ' OK'
|
@ -1,37 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -static --filler 0xfe -o %t1.exe \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: mold -static --filler 0x0 -o %t2.exe \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: hexdump -C %t1.exe > %t1.txt
|
||||
// RUN: hexdump -C %t2.exe > %t2.txt
|
||||
// RUN: diff %t1.txt %t2.txt
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
49
test/filler.sh
Executable file
49
test/filler.sh
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../mold -static --filler 0xfe -o $t/exe1 \
|
||||
/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 > /dev/null
|
||||
|
||||
../mold -static --filler 0x0 -o $t/exe2 \
|
||||
/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 > /dev/null
|
||||
|
||||
hexdump -C $t/exe1 > $t/txt1
|
||||
hexdump -C $t/exe2 > $t/txt2
|
||||
|
||||
diff -q $t/txt1 $t/txt2
|
||||
|
||||
echo ' OK'
|
@ -1,26 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
36
test/hello-dynamic.sh
Executable file
36
test/hello-dynamic.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,24 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -static -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
34
test/hello-static.sh
Executable file
34
test/hello-static.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../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 > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,25 +0,0 @@
|
||||
// RUN: cc -shared -fPIC -o %t.so %p/input/ifunc-dso.s
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: %t.so \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
call foobar@PLT
|
||||
xor %rax, %rax
|
||||
popq %rbp
|
||||
ret
|
60
test/ifunc-dso.sh
Executable file
60
test/ifunc-dso.sh
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
call foobar@PLT
|
||||
xor %rax, %rax
|
||||
popq %rbp
|
||||
ret
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -shared -fPIC -o $t/b.so -x assembler -
|
||||
.text
|
||||
real_foobar:
|
||||
lea .Lmsg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.globl resolve_foobar
|
||||
resolve_foobar:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movq real_foobar@GOTPCREL(%rip), %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.globl foobar
|
||||
.type foobar, @gnu_indirect_function
|
||||
.set foobar, resolve_foobar
|
||||
|
||||
.data
|
||||
.Lmsg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o \
|
||||
$t/b.so \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,47 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl real_foobar
|
||||
real_foobar:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.globl resolve_foobar
|
||||
resolve_foobar:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
leaq real_foobar(%rip), %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.globl foobar
|
||||
.type foobar, @gnu_indirect_function
|
||||
.set foobar, resolve_foobar
|
||||
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
call foobar@PLT
|
||||
xor %rax, %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
57
test/ifunc-dynamic.sh
Executable file
57
test/ifunc-dynamic.sh
Executable file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl real_foobar
|
||||
real_foobar:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.globl resolve_foobar
|
||||
resolve_foobar:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
leaq real_foobar(%rip), %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.globl foobar
|
||||
.type foobar, @gnu_indirect_function
|
||||
.set foobar, resolve_foobar
|
||||
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
call foobar@PLT
|
||||
xor %rax, %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,45 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -static -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl real_foobar
|
||||
real_foobar:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.globl resolve_foobar
|
||||
resolve_foobar:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
leaq real_foobar(%rip), %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.globl foobar
|
||||
.type foobar, @gnu_indirect_function
|
||||
.set foobar, resolve_foobar
|
||||
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
call foobar@PLT
|
||||
xor %rax, %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
56
test/ifunc-static.sh
Executable file
56
test/ifunc-static.sh
Executable file
@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl real_foobar
|
||||
real_foobar:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.globl resolve_foobar
|
||||
resolve_foobar:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
leaq real_foobar(%rip), %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.globl foobar
|
||||
.type foobar, @gnu_indirect_function
|
||||
.set foobar, resolve_foobar
|
||||
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
call foobar@PLT
|
||||
xor %rax, %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
|
||||
../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 > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,23 +0,0 @@
|
||||
.text
|
||||
real_foobar:
|
||||
lea .Lmsg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.globl resolve_foobar
|
||||
resolve_foobar:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movq real_foobar@GOTPCREL(%rip), %rax
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.globl foobar
|
||||
.type foobar, @gnu_indirect_function
|
||||
.set foobar, resolve_foobar
|
||||
|
||||
.data
|
||||
.Lmsg:
|
||||
.string "Hello world\n"
|
@ -1,45 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
|
||||
// RUN: mold -o %t.exe \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: -L/usr/lib/gcc/x86_64-linux-gnu/9 \
|
||||
// RUN: -L/usr/lib/x86_64-linux-gnu \
|
||||
// RUN: -L/usr/lib64 \
|
||||
// RUN: -L/lib/x86_64-linux-gnu \
|
||||
// RUN: -L/lib64 \
|
||||
// RUN: -L/usr/lib/x86_64-linux-gnu \
|
||||
// RUN: -L/usr/lib64 \
|
||||
// RUN: -L/usr/lib64 \
|
||||
// RUN: -L/usr/lib \
|
||||
// RUN: -L/usr/lib/llvm-10/lib \
|
||||
// RUN: -L/lib \
|
||||
// RUN: -L/usr/lib \
|
||||
// RUN: %t.o \
|
||||
// RUN: -lgcc \
|
||||
// RUN: --as-needed \
|
||||
// RUN: -lgcc_s \
|
||||
// RUN: --no-as-needed \
|
||||
// RUN: -lc \
|
||||
// RUN: -lgcc \
|
||||
// RUN: --as-needed \
|
||||
// RUN: -lgcc_s \
|
||||
// RUN: --no-as-needed \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
53
test/library-path-dynamic.sh
Executable file
53
test/library-path-dynamic.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
-L/usr/lib/gcc/x86_64-linux-gnu/9 \
|
||||
-L/usr/lib/x86_64-linux-gnu \
|
||||
-L/usr/lib64 \
|
||||
-L/lib/x86_64-linux-gnu \
|
||||
-L/lib64 \
|
||||
-L/usr/lib/x86_64-linux-gnu \
|
||||
-L/usr/lib64 \
|
||||
-L/usr/lib64 \
|
||||
-L/usr/lib \
|
||||
-L/usr/lib/llvm-10/lib \
|
||||
-L/lib \
|
||||
-L/usr/lib \
|
||||
$t/a.o \
|
||||
-lgcc \
|
||||
--as-needed \
|
||||
-lgcc_s \
|
||||
--no-as-needed \
|
||||
-lc \
|
||||
-lgcc \
|
||||
--as-needed \
|
||||
-lgcc_s \
|
||||
--no-as-needed \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,36 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -static -o %t.exe \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||
// RUN: -L/usr/lib/gcc/x86_64-linux-gnu/9 \
|
||||
// RUN: -L/usr/lib/x86_64-linux-gnu \
|
||||
// RUN: -L/usr/lib64 \
|
||||
// RUN: -L/lib/x86_64-linux-gnu \
|
||||
// RUN: -L/lib64 \
|
||||
// RUN: -L/usr/lib/x86_64-linux-gnu \
|
||||
// RUN: -L/usr/lib64 \
|
||||
// RUN: -L/usr/lib64 \
|
||||
// RUN: -L/usr/lib \
|
||||
// RUN: -L/lib \
|
||||
// RUN: -L/usr/lib \
|
||||
// RUN: %t.o \
|
||||
// RUN: -lgcc \
|
||||
// RUN: -lgcc_eh \
|
||||
// RUN: -lc \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
47
test/library-path-static.sh
Executable file
47
test/library-path-static.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
|
||||
../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 \
|
||||
-L/usr/lib/gcc/x86_64-linux-gnu/9 \
|
||||
-L/usr/lib/x86_64-linux-gnu \
|
||||
-L/usr/lib64 \
|
||||
-L/lib/x86_64-linux-gnu \
|
||||
-L/lib64 \
|
||||
-L/usr/lib/x86_64-linux-gnu \
|
||||
-L/usr/lib64 \
|
||||
-L/usr/lib64 \
|
||||
-L/usr/lib \
|
||||
-L/lib \
|
||||
-L/usr/lib \
|
||||
$t/a.o \
|
||||
-lgcc \
|
||||
-lgcc_eh \
|
||||
-lc \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
42
test/linker-script.sh
Executable file
42
test/linker-script.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
cat <<EOF > $t/script
|
||||
GROUP (
|
||||
/lib/x86_64-linux-gnu/libc.so.6
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a
|
||||
AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 )
|
||||
)
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
$t/script \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,25 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: echo 'GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) )' > %t.script
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: %t.script \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
@ -1,22 +0,0 @@
|
||||
# -*- Python -*-
|
||||
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import locale
|
||||
|
||||
from lit.llvm import llvm_config
|
||||
import lit.llvm
|
||||
import lit.util
|
||||
|
||||
config.name = 'mold'
|
||||
config.suffixes = ['.c', '.s', '.test']
|
||||
config.excludes = ['input']
|
||||
config.test_format = lit.formats.ShTest(False)
|
||||
config.test_source_root = os.path.dirname(__file__)
|
||||
|
||||
config.environment['PATH'] = os.path.pathsep.join((
|
||||
os.path.dirname(__file__) + '/..',
|
||||
os.path.dirname(__file__) + '/../llvm-project/build/bin',
|
||||
config.environment['PATH']))
|
@ -1,29 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -static -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep 'Hello world'
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
mov $.L.str+3, %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
mov $.rodata.str1.1+16, %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.section .rodata.str1.1, "aMS", @progbits, 1
|
||||
.string "bar"
|
||||
.L.str:
|
||||
.string "xyzHello"
|
||||
.string "foo world\n"
|
39
test/mergeable-strings.sh
Executable file
39
test/mergeable-strings.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
mov $.L.str+3, %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
mov $.rodata.str1.1+16, %rdi
|
||||
xor %rax, %rax
|
||||
call printf
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.section .rodata.str1.1, "aMS", @progbits, 1
|
||||
.string "bar"
|
||||
.L.str:
|
||||
.string "xyzHello"
|
||||
.string "foo world\n"
|
||||
EOF
|
||||
|
||||
../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 > /dev/null
|
||||
|
||||
$t/exe | grep -q 'Hello world'
|
||||
|
||||
echo ' OK'
|
@ -1,7 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe %t.o
|
||||
|
||||
.text
|
||||
.globl _start, foo
|
||||
_start:
|
||||
nop
|
16
test/missing-but-ok.sh
Executable file
16
test/missing-but-ok.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl _start, foo
|
||||
_start:
|
||||
nop
|
||||
EOF
|
||||
|
||||
../mold -o $t/exe $t/a.o > /dev/null
|
||||
|
||||
echo ' OK'
|
@ -1,8 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: not mold -o %t.exe %t.o 2> %t.log
|
||||
// RUN: grep 'undefined symbol: .*\.o: foo' %t.log
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
call foo
|
17
test/missing-error.sh
Executable file
17
test/missing-error.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
call foo
|
||||
EOF
|
||||
|
||||
! ../mold -o $t/exe $t/a.o 2> $t/log
|
||||
grep -q 'undefined symbol: .*\.o: foo' $t/log
|
||||
|
||||
echo ' OK'
|
47
test/plt.s
47
test/plt.s
@ -1,47 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
|
||||
|
||||
// RUN: readelf --sections %t.exe | FileCheck --check-prefix=SECTIONS %s
|
||||
// SECTIONS: [17] .got PROGBITS 0000000000202000 00002000
|
||||
// SECTIONS: 0000000000000028 0000000000000000 WA 0 0 8
|
||||
// SECTIONS: [18] .got.plt PROGBITS 0000000000202028 00002028
|
||||
// SECTIONS: 0000000000000020 0000000000000000 WA 0 0 8
|
||||
|
||||
// RUN: readelf -x .got.plt %t.exe | FileCheck --check-prefix=GOTPLT %s
|
||||
// GOTPLT: Hex dump of section '.got.plt':
|
||||
// GOTPLT: 0x00202028 48202000 00000000 00000000 00000000 H .............
|
||||
// GOTPLT: 0x00202038 00000000 00000000 16102000 00000000 .......... .....
|
||||
|
||||
// RUN: objdump -d -j .plt %t.exe | FileCheck --check-prefix=PLT %s
|
||||
// PLT: Disassembly of section .plt:
|
||||
// PLT: 0000000000201000 <printf@plt-0x10>:
|
||||
// PLT: 201000: ff 35 2a 10 00 00 pushq 0x102a(%rip) # 202030 <_GLOBAL_OFFSET_TABLE_+0x8>
|
||||
// PLT: 201006: ff 25 2c 10 00 00 jmpq *0x102c(%rip) # 202038 <_GLOBAL_OFFSET_TABLE_+0x10>
|
||||
// PLT: 20100c: 0f 1f 40 00 nopl 0x0(%rax)
|
||||
// PLT: 0000000000201010 <printf@plt>:
|
||||
// PLT: 201010: ff 25 2a 10 00 00 jmpq *0x102a(%rip) # 202040 <printf@GLIBC_2.2.5>
|
||||
// PLT: 201016: 68 00 00 00 00 pushq $0x0
|
||||
// PLT: 20101b: e9 e0 ff ff ff jmpq 201000 <_IO_stdin_used+0xb80>
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
61
test/plt.sh
Executable file
61
test/plt.sh
Executable file
@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
lea msg(%rip), %rdi
|
||||
xor %rax, %rax
|
||||
call printf@PLT
|
||||
xor %rax, %rax
|
||||
ret
|
||||
|
||||
.data
|
||||
msg:
|
||||
.string "Hello world\n"
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 > /dev/null
|
||||
|
||||
readelf --sections $t/exe | grep -q "
|
||||
[17] .got PROGBITS 0000000000202000 00002000
|
||||
0000000000000028 0000000000000000 WA 0 0 8
|
||||
[18] .got.plt PROGBITS 0000000000202028 00002028
|
||||
0000000000000020 0000000000000000 WA 0 0 8
|
||||
"
|
||||
|
||||
readelf -x .got.plt $t/exe | grep -q "
|
||||
Hex dump of section '.got.plt':
|
||||
0x00202028 48202000 00000000 00000000 00000000 H .............
|
||||
0x00202038 00000000 00000000 16102000 00000000 .......... .....
|
||||
"
|
||||
|
||||
objdump -d -j .plt $t/exe | grep -q "
|
||||
Disassembly of section .plt:
|
||||
|
||||
0000000000201000 <printf@plt-0x10>:
|
||||
201000: ff 35 2a 10 00 00 pushq 0x102a(%rip) # 202030 <_GLOBAL_OFFSET_TABLE_+0x8>
|
||||
201006: ff 25 2c 10 00 00 jmpq *0x102c(%rip) # 202038 <_GLOBAL_OFFSET_TABLE_+0x10>
|
||||
20100c: 0f 1f 40 00 nopl 0x0(%rax)
|
||||
|
||||
0000000000201010 <printf@plt>:
|
||||
201010: ff 25 2a 10 00 00 jmpq *0x102a(%rip) # 202040 <printf@GLIBC_2.2.5>
|
||||
201016: 68 00 00 00 00 pushq $0x0
|
||||
20101b: e9 e0 ff ff ff jmpq 201000 <_IO_stdin_used+0xb80>
|
||||
"
|
||||
|
||||
echo ' OK'
|
10
test/rpath.s
10
test/rpath.s
@ -1,10 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe %t.o -rpath /foo -rpath /bar
|
||||
// RUN: readelf --dynamic %t.exe | FileCheck %s
|
||||
// CHECK: 0x000000000000001d (RUNPATH) Library runpath: [/foo]
|
||||
// CHECK: 0x000000000000001d (RUNPATH) Library runpath: [/bar]
|
||||
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
nop
|
21
test/rpath.sh
Executable file
21
test/rpath.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
nop
|
||||
EOF
|
||||
|
||||
../mold -o $t/exe $t/a.o -rpath /foo -rpath /bar > /dev/null
|
||||
|
||||
readelf --dynamic $t/exe | grep -q "
|
||||
0x000000000000001d (RUNPATH) Library runpath: [/foo]
|
||||
0x000000000000001d (RUNPATH) Library runpath: [/bar]
|
||||
"
|
||||
|
||||
echo ' OK'
|
@ -1,35 +0,0 @@
|
||||
// RUN: cc -o %t1.o -c %s
|
||||
// RUN: echo '.globl this_is_global; local2: this_is_global:' | \
|
||||
// RUN: cc -x assembler -o %t2.o -c -
|
||||
// RUN: mold -o %t.exe %t1.o %t2.o
|
||||
// RUN: readelf --symbols %t.exe | FileCheck %s
|
||||
|
||||
// CHECK: Symbol table '.symtab' contains 21 entries:
|
||||
// CHECK: Num: Value Size Type Bind Vis Ndx Name
|
||||
// CHECK: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
||||
// CHECK: 1: 0000000000201010 0 NOTYPE LOCAL DEFAULT 6 local1
|
||||
// CHECK: 2: 0000000000201011 0 NOTYPE LOCAL DEFAULT 6 local2
|
||||
// CHECK: 3: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 6 foo
|
||||
// CHECK: 4: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 6 bar
|
||||
// CHECK: 5: 0000000000201011 0 NOTYPE GLOBAL DEFAULT 6 this_is_global
|
||||
// CHECK: 6: 0000000000200000 0 NOTYPE GLOBAL HIDDEN 1 __ehdr_start
|
||||
// CHECK: 7: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __rela_iplt_start
|
||||
// CHECK: 8: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __rela_iplt_end
|
||||
// CHECK: 9: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __init_array_start
|
||||
// CHECK: 10: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __init_array_end
|
||||
// CHECK: 11: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __fini_array_start
|
||||
// CHECK: 12: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __fini_array_end
|
||||
// CHECK: 13: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __preinit_array_start
|
||||
// CHECK: 14: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __preinit_array_end
|
||||
// CHECK: 15: 0000000000202018 0 NOTYPE GLOBAL HIDDEN 8 _DYNAMIC
|
||||
// CHECK: 16: 0000000000202000 0 NOTYPE GLOBAL HIDDEN 7 _GLOBAL_OFFSET_TABLE_
|
||||
// CHECK: 17: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __bss_start
|
||||
// CHECK: 18: 0000000000202168 0 NOTYPE GLOBAL HIDDEN 8 _end
|
||||
// CHECK: 19: 0000000000201011 0 NOTYPE GLOBAL HIDDEN 6 _etext
|
||||
// CHECK: 20: 0000000000202168 0 NOTYPE GLOBAL HIDDEN 8 _edata
|
||||
|
||||
.globl foo, bar, this_is_global
|
||||
local1:
|
||||
foo:
|
||||
bar:
|
||||
.byte 0
|
49
test/symtab.sh
Executable file
49
test/symtab.sh
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.globl foo, bar, this_is_global
|
||||
local1:
|
||||
foo:
|
||||
bar:
|
||||
.byte 0
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -o $t/b.o -c -x assembler -
|
||||
.globl this_is_global
|
||||
local2:
|
||||
this_is_global:
|
||||
EOF
|
||||
|
||||
../mold -o $t/exe $t/a.o $t/b.o > /dev/null
|
||||
|
||||
readelf --symbols $t/exe | grep -q "
|
||||
Symbol table '.symtab' contains 21 entries:
|
||||
Num: Value Size Type Bind Vis Ndx Name
|
||||
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
||||
1: 0000000000201010 0 NOTYPE LOCAL DEFAULT 6 local1
|
||||
2: 0000000000201011 0 NOTYPE LOCAL DEFAULT 6 local2
|
||||
3: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 6 foo
|
||||
4: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 6 bar
|
||||
5: 0000000000201011 0 NOTYPE GLOBAL DEFAULT 6 this_is_global
|
||||
6: 0000000000200000 0 NOTYPE GLOBAL HIDDEN 1 __ehdr_start
|
||||
7: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __rela_iplt_start
|
||||
8: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __rela_iplt_end
|
||||
9: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __init_array_start
|
||||
10: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __init_array_end
|
||||
11: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __fini_array_start
|
||||
12: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __fini_array_end
|
||||
13: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __preinit_array_start
|
||||
14: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __preinit_array_end
|
||||
15: 0000000000202018 0 NOTYPE GLOBAL HIDDEN 8 _DYNAMIC
|
||||
16: 0000000000202000 0 NOTYPE GLOBAL HIDDEN 7 _GLOBAL_OFFSET_TABLE_
|
||||
17: 0000000000000000 0 NOTYPE GLOBAL HIDDEN ABS __bss_start
|
||||
18: 0000000000202168 0 NOTYPE GLOBAL HIDDEN 8 _end
|
||||
19: 0000000000201011 0 NOTYPE GLOBAL HIDDEN 6 _etext
|
||||
20: 0000000000202168 0 NOTYPE GLOBAL HIDDEN 8 _edata
|
||||
"
|
||||
|
||||
echo ' OK'
|
@ -1,29 +0,0 @@
|
||||
// RUN: cc -fPIC -c -o %t1.o %s
|
||||
// RUN: echo '_Thread_local int foo = 3;' | cc -xc -shared -fPIC -o %t2.so -
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t1.o %t2.so \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep '3 5 3 5'
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
42
test/tls-gd.sh
Executable file
42
test/tls-gd.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -fPIC -c -o $t/a.o -xc -
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -fPIC -shared -o $t/b.so -xc -
|
||||
_Thread_local int foo = 3;
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o $t/b.so \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q '3 5 3 5'
|
||||
|
||||
echo ' OK'
|
@ -1,29 +0,0 @@
|
||||
// RUN: cc -ftls-model=local-dynamic -fPIC -c -o %t1.o %s
|
||||
// RUN: echo '_Thread_local int foo = 3;' | cc -xc -c -fPIC -o %t2.o -
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t1.o %t2.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep '3 5 3 5'
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
42
test/tls-ld.sh
Executable file
42
test/tls-ld.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -ftls-model=local-dynamic -fPIC -c -o $t/a.o -xc -
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -xc -c -fPIC -o $t/b.o -
|
||||
_Thread_local int foo = 3;
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o $t/b.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q '3 5 3 5'
|
||||
|
||||
echo ' OK'
|
@ -1,30 +0,0 @@
|
||||
// RUN: cc -c -o %t1.o %s
|
||||
// RUN: echo '_Thread_local int foo;' | cc -xc -c -o %t2.o -
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t1.o %t2.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep '3 5 3 5'
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
foo = 3;
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
43
test/tls-nopic.sh
Executable file
43
test/tls-nopic.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -c -o $t/a.o -xc -
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
foo = 3;
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -xc -c -o $t/b.o -
|
||||
_Thread_local int foo;
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o $t/b.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q '3 5 3 5'
|
||||
|
||||
echo ' OK'
|
@ -1,29 +0,0 @@
|
||||
// RUN: cc -fPIC -c -o %t1.o %s
|
||||
// RUN: echo '_Thread_local int foo = 3;' | cc -xc -c -o %t2.o -
|
||||
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||
// RUN: %t1.o %t2.o \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||
// RUN: %t.exe | grep '3 5 3 5'
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
42
test/tls-pic.sh
Executable file
42
test/tls-pic.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -fPIC -c -o $t/a.o -xc -
|
||||
#include <stdio.h>
|
||||
|
||||
extern _Thread_local int foo;
|
||||
static _Thread_local int bar;
|
||||
|
||||
int *get_foo_addr() { return &foo; }
|
||||
int *get_bar_addr() { return &bar; }
|
||||
|
||||
int main() {
|
||||
bar = 5;
|
||||
|
||||
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -xc -c -o $t/b.o -
|
||||
_Thread_local int foo = 3;
|
||||
EOF
|
||||
|
||||
../mold -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/crtbegin.o \
|
||||
$t/a.o $t/b.o \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||
/usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||
/lib/x86_64-linux-gnu/libc.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||
/usr/lib/x86_64-linux-gnu/crtn.o > /dev/null
|
||||
|
||||
$t/exe | grep -q '3 5 3 5'
|
||||
|
||||
echo ' OK'
|
@ -1,8 +0,0 @@
|
||||
// RUN: cc -o %t.o -c %s
|
||||
// RUN: mold -o %t.exe %t.o
|
||||
// RUN: readelf -a %t.exe
|
||||
|
||||
.weak weak_fn
|
||||
.global _start
|
||||
_start:
|
||||
nop
|
18
test/weak-export.sh
Executable file
18
test/weak-export.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo -n "Testing $(basename -s .sh $0) ..."
|
||||
t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.weak weak_fn
|
||||
.global _start
|
||||
_start:
|
||||
nop
|
||||
EOF
|
||||
|
||||
|
||||
../mold -o $t/exe $t/a.o > /dev/null
|
||||
readelf -a $t/exe > /dev/null
|
||||
|
||||
echo ' OK'
|
Loading…
Reference in New Issue
Block a user