Skip to content

Commit

Permalink
temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Dec 11, 2020
1 parent 48178b2 commit cf22ce3
Show file tree
Hide file tree
Showing 58 changed files with 1,041 additions and 767 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.o
*~
/mold
/test/Output
/test/tmp
options.inc
core
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

Expand Down
2 changes: 1 addition & 1 deletion object_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down
20 changes: 0 additions & 20 deletions test/as-needed.s

This file was deleted.

34 changes: 34 additions & 0 deletions test/as-needed.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions test/basic.sh
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 0 additions & 5 deletions test/basic.test

This file was deleted.

24 changes: 0 additions & 24 deletions test/copyrel.c

This file was deleted.

41 changes: 41 additions & 0 deletions test/copyrel.sh
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 0 additions & 8 deletions test/duplicate-error.s

This file was deleted.

17 changes: 17 additions & 0 deletions test/duplicate-error.sh
Original file line number Diff line number Diff line change
@@ -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'
52 changes: 0 additions & 52 deletions test/dynamic.s

This file was deleted.

59 changes: 59 additions & 0 deletions test/dynamic.sh
Original file line number Diff line number Diff line change
@@ -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'
38 changes: 0 additions & 38 deletions test/export-dynamic.s

This file was deleted.

Loading

0 comments on commit cf22ce3

Please sign in to comment.