mirror of
https://github.com/rui314/mold.git
synced 2024-12-26 01:44:29 +03:00
temporary
This commit is contained in:
parent
c3ace840d8
commit
5a57684b84
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ LLVM_LIBS=$(wildcard llvm-project/build/lib/libLLVM*.a)
|
|||||||
CURRENT_DIR=$(shell pwd)
|
CURRENT_DIR=$(shell pwd)
|
||||||
TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/)
|
TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/)
|
||||||
|
|
||||||
CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread -std=c++17 -O2
|
CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread -std=c++17
|
||||||
LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) -fuse-ld=lld -Wl,-hash-style=sysv
|
LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) -fuse-ld=lld -Wl,-hash-style=sysv
|
||||||
LIBS=-pthread -ltbb -lcurses -Wl,--start-group $(LLVM_LIBS) -Wl,--end-group
|
LIBS=-pthread -ltbb -lcurses -Wl,--start-group $(LLVM_LIBS) -Wl,--end-group
|
||||||
OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o
|
OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o
|
||||||
|
18
main.cc
18
main.cc
@ -414,17 +414,12 @@ static void write_got(u8 *buf, ArrayRef<ObjectFile *> files) {
|
|||||||
u8 *got = buf + out::got->shdr.sh_offset;
|
u8 *got = buf + out::got->shdr.sh_offset;
|
||||||
u8 *plt = buf + out::plt->shdr.sh_offset;
|
u8 *plt = buf + out::plt->shdr.sh_offset;
|
||||||
u8 *relplt = buf + out::relplt->shdr.sh_offset;
|
u8 *relplt = buf + out::relplt->shdr.sh_offset;
|
||||||
u8 *dynsym = nullptr;
|
u8 *dynsym = buf + out::dynsym->shdr.sh_offset;
|
||||||
u8 *dynstr = nullptr;
|
u8 *dynstr = buf + out::dynstr->shdr.sh_offset;
|
||||||
|
|
||||||
memset(buf + out::gotplt->shdr.sh_offset, 0, out::gotplt->shdr.sh_size);
|
memset(buf + out::gotplt->shdr.sh_offset, 0, out::gotplt->shdr.sh_size);
|
||||||
|
|
||||||
if (out::dynstr) {
|
|
||||||
dynsym = buf + out::dynsym->shdr.sh_offset;
|
|
||||||
dynstr = buf + out::dynstr->shdr.sh_offset;
|
|
||||||
memset(dynsym, 0, sizeof(ELF64LE::Sym));
|
memset(dynsym, 0, sizeof(ELF64LE::Sym));
|
||||||
dynstr[0] = '\0';
|
dynstr[0] = '\0';
|
||||||
}
|
|
||||||
|
|
||||||
tbb::parallel_for_each(files, [&](ObjectFile *file) {
|
tbb::parallel_for_each(files, [&](ObjectFile *file) {
|
||||||
u32 dynstr_offset = file->dynstr_offset;
|
u32 dynstr_offset = file->dynstr_offset;
|
||||||
@ -943,20 +938,21 @@ int main(int argc, char **argv) {
|
|||||||
out::shstrtab = new ShstrtabSection;
|
out::shstrtab = new ShstrtabSection;
|
||||||
out::plt = new PltSection;
|
out::plt = new PltSection;
|
||||||
out::symtab = new SymtabSection(".symtab", 0);
|
out::symtab = new SymtabSection(".symtab", 0);
|
||||||
|
out::dynsym = new SymtabSection(".dynsym", SHF_ALLOC);
|
||||||
|
out::dynstr = new SpecialSection(".dynstr", SHT_STRTAB, SHF_ALLOC);
|
||||||
|
|
||||||
|
out::dynsym->shdr.sh_size = sizeof(ELF64LE::Sym);
|
||||||
|
out::dynstr->shdr.sh_size = 1;
|
||||||
|
|
||||||
if (!config.is_static) {
|
if (!config.is_static) {
|
||||||
out::interp = new SpecialSection(".interp", SHT_PROGBITS, SHF_ALLOC);
|
out::interp = new SpecialSection(".interp", SHT_PROGBITS, SHF_ALLOC);
|
||||||
out::dynamic = new SpecialSection(".dynamic", SHT_DYNAMIC, SHF_ALLOC | SHF_WRITE,
|
out::dynamic = new SpecialSection(".dynamic", SHT_DYNAMIC, SHF_ALLOC | SHF_WRITE,
|
||||||
8, sizeof(ELF64LE::Dyn));
|
8, sizeof(ELF64LE::Dyn));
|
||||||
out::dynstr = new SpecialSection(".dynstr", SHT_STRTAB, SHF_ALLOC);
|
|
||||||
out::dynsym = new SymtabSection(".dynsym", SHF_ALLOC);
|
|
||||||
out::reldyn = new SpecialSection(".rela.dyn", SHT_RELA, SHF_ALLOC, 8,
|
out::reldyn = new SpecialSection(".rela.dyn", SHT_RELA, SHF_ALLOC, 8,
|
||||||
sizeof(ELF64LE::Rela));
|
sizeof(ELF64LE::Rela));
|
||||||
out::hash = new HashSection;
|
out::hash = new HashSection;
|
||||||
|
|
||||||
out::interp->shdr.sh_size = config.dynamic_linker.size() + 1;
|
out::interp->shdr.sh_size = config.dynamic_linker.size() + 1;
|
||||||
out::dynstr->shdr.sh_size = 1;
|
|
||||||
out::dynsym->shdr.sh_size = sizeof(ELF64LE::Sym);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set priorities to files
|
// Set priorities to files
|
||||||
|
2
mold.h
2
mold.h
@ -532,7 +532,7 @@ public:
|
|||||||
void write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
|
void write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
|
||||||
void write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
|
void write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
|
||||||
|
|
||||||
static ObjectFile *create_internal_file(ArrayRef<OutputChunk *> chunks);
|
static ObjectFile *create_internal_file(std::vector<OutputChunk *> chunks);
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
StringRef archive_name;
|
StringRef archive_name;
|
||||||
|
@ -515,7 +515,7 @@ bool is_c_identifier(StringRef name) {
|
|||||||
return std::regex_match(name.begin(), name.end(), re);
|
return std::regex_match(name.begin(), name.end(), re);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectFile *ObjectFile::create_internal_file(ArrayRef<OutputChunk *> chunks) {
|
ObjectFile *ObjectFile::create_internal_file(std::vector<OutputChunk *> chunks) {
|
||||||
// Create a dummy object file.
|
// Create a dummy object file.
|
||||||
constexpr int bufsz = 256;
|
constexpr int bufsz = 256;
|
||||||
char *buf = new char[bufsz];
|
char *buf = new char[bufsz];
|
||||||
@ -566,6 +566,10 @@ ObjectFile *ObjectFile::create_internal_file(ArrayRef<OutputChunk *> chunks) {
|
|||||||
out::_etext = add("_etext", STB_GLOBAL);
|
out::_etext = add("_etext", STB_GLOBAL);
|
||||||
out::_edata = add("_edata", STB_GLOBAL);
|
out::_edata = add("_edata", STB_GLOBAL);
|
||||||
|
|
||||||
|
std::sort(chunks.begin(), chunks.end(), [](OutputChunk *x, OutputChunk *y) {
|
||||||
|
return x->name < y->name;
|
||||||
|
});
|
||||||
|
|
||||||
for (OutputChunk *chunk : chunks) {
|
for (OutputChunk *chunk : chunks) {
|
||||||
if (!is_c_identifier(chunk->name))
|
if (!is_c_identifier(chunk->name))
|
||||||
continue;
|
continue;
|
||||||
|
11
test/dynamic.s
Normal file
11
test/dynamic.s
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// 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
|
@ -1,5 +1,5 @@
|
|||||||
// RUN: cc -o %t.o -c %s
|
// RUN: cc -o %t.o -c %s
|
||||||
// RUN: mold -static --filler=0xfe -o %t1.exe \
|
// RUN: mold -static --filler 0xfe -o %t1.exe \
|
||||||
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||||
@ -9,7 +9,7 @@
|
|||||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||||
// RUN: mold -static --filler=0 -o %t2.exe \
|
// RUN: mold -static --filler 0x0 -o %t2.exe \
|
||||||
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
// RUN: /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||||
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \
|
||||||
@ -19,7 +19,9 @@
|
|||||||
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
// RUN: /usr/lib/x86_64-linux-gnu/libc.a \
|
||||||
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||||
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||||
// RUN: diff %t1.exe %t2.exe
|
// RUN: hexdump -C %t1.exe > %t1.txt
|
||||||
|
// RUN: hexdump -C %t2.exe > %t2.txt
|
||||||
|
// RUN: diff %t1.txt %t2.txt
|
||||||
|
|
||||||
.text
|
.text
|
||||||
.globl main
|
.globl main
|
||||||
|
Loading…
Reference in New Issue
Block a user