mirror of
https://github.com/rui314/mold.git
synced 2024-09-22 02:20:51 +03:00
temporary
This commit is contained in:
parent
7448940d79
commit
e260e8dc5b
@ -68,7 +68,7 @@ void InputSection::relocate(u8 *buf) {
|
|||||||
|
|
||||||
u64 P = output_section->shdr.sh_addr + offset + rel.r_offset;
|
u64 P = output_section->shdr.sh_addr + offset + rel.r_offset;
|
||||||
u64 S = sym ? sym->addr : file->get_symbol_addr(sym_idx);
|
u64 S = sym ? sym->addr : file->get_symbol_addr(sym_idx);
|
||||||
u64 A = rel.r_addend;
|
i64 A = rel.r_addend;
|
||||||
u64 G = sym ? sym->got_addr : 0;
|
u64 G = sym ? sym->got_addr : 0;
|
||||||
u64 GOT = out::got->shdr.sh_addr;
|
u64 GOT = out::got->shdr.sh_addr;
|
||||||
|
|
||||||
@ -85,7 +85,8 @@ void InputSection::relocate(u8 *buf) {
|
|||||||
*(u64 *)loc = G + A;
|
*(u64 *)loc = G + A;
|
||||||
break;
|
break;
|
||||||
case R_X86_64_PLT32:
|
case R_X86_64_PLT32:
|
||||||
break; // todo
|
*(u32 *)loc = S + A - P; // todo
|
||||||
|
break;
|
||||||
case R_X86_64_GOTPCREL:
|
case R_X86_64_GOTPCREL:
|
||||||
*(u32 *)loc = G + GOT + A - P;
|
*(u32 *)loc = G + GOT + A - P;
|
||||||
break;
|
break;
|
||||||
|
37
main.cc
37
main.cc
@ -291,13 +291,15 @@ static u64 set_osec_offsets(ArrayRef<OutputChunk *> output_chunks) {
|
|||||||
u64 vaddr = 0x200000;
|
u64 vaddr = 0x200000;
|
||||||
|
|
||||||
for (OutputChunk *chunk : output_chunks) {
|
for (OutputChunk *chunk : output_chunks) {
|
||||||
if (chunk->starts_new_ptload) {
|
if (chunk->starts_new_ptload)
|
||||||
fileoff = align_to(fileoff, PAGE_SIZE);
|
|
||||||
vaddr = align_to(vaddr, PAGE_SIZE);
|
vaddr = align_to(vaddr, PAGE_SIZE);
|
||||||
}
|
|
||||||
|
|
||||||
if (!chunk->is_bss())
|
if (vaddr % PAGE_SIZE < fileoff % PAGE_SIZE)
|
||||||
fileoff = align_to(fileoff, chunk->shdr.sh_addralign);
|
fileoff += vaddr % PAGE_SIZE - fileoff % PAGE_SIZE;
|
||||||
|
else if (vaddr % PAGE_SIZE > fileoff % PAGE_SIZE)
|
||||||
|
fileoff = align_to(fileoff, PAGE_SIZE) + vaddr % PAGE_SIZE;
|
||||||
|
|
||||||
|
fileoff = align_to(fileoff, chunk->shdr.sh_addralign);
|
||||||
vaddr = align_to(vaddr, chunk->shdr.sh_addralign);
|
vaddr = align_to(vaddr, chunk->shdr.sh_addralign);
|
||||||
|
|
||||||
chunk->shdr.sh_offset = fileoff;
|
chunk->shdr.sh_offset = fileoff;
|
||||||
@ -306,7 +308,10 @@ static u64 set_osec_offsets(ArrayRef<OutputChunk *> output_chunks) {
|
|||||||
|
|
||||||
if (!chunk->is_bss())
|
if (!chunk->is_bss())
|
||||||
fileoff += chunk->get_size();
|
fileoff += chunk->get_size();
|
||||||
vaddr += chunk->get_size();
|
|
||||||
|
bool is_tbss = chunk->is_bss() && (chunk->shdr.sh_flags & SHF_TLS);
|
||||||
|
if (!is_tbss)
|
||||||
|
vaddr += chunk->get_size();
|
||||||
}
|
}
|
||||||
return fileoff;
|
return fileoff;
|
||||||
}
|
}
|
||||||
@ -506,7 +511,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
for (ObjectFile *file : files) {
|
for (ObjectFile *file : files) {
|
||||||
for (Symbol *sym : file->symbols) {
|
for (Symbol *sym : file->symbols) {
|
||||||
if (sym->file == file && sym->needs_got) {
|
if (sym->file == file && sym->needs_got) {
|
||||||
out::got->symbols.push_back(sym);
|
out::got->symbols.push_back(sym);
|
||||||
sym->got_addr = offset;
|
sym->got_addr = offset;
|
||||||
offset += 8;
|
offset += 8;
|
||||||
@ -575,14 +580,20 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create an output file
|
// Create an output file
|
||||||
Expected<std::unique_ptr<FileOutputBuffer>> buf_or_err =
|
std::unique_ptr<FileOutputBuffer> output_buffer;
|
||||||
FileOutputBuffer::create(config.output, filesize, FileOutputBuffer::F_executable);
|
|
||||||
|
|
||||||
if (!buf_or_err)
|
{
|
||||||
error("failed to open " + config.output + ": " +
|
MyTimer t("open");
|
||||||
llvm::toString(buf_or_err.takeError()));
|
Expected<std::unique_ptr<FileOutputBuffer>> buf_or_err =
|
||||||
|
FileOutputBuffer::create(config.output, filesize, FileOutputBuffer::F_executable);
|
||||||
|
|
||||||
|
if (!buf_or_err)
|
||||||
|
error("failed to open " + config.output + ": " +
|
||||||
|
llvm::toString(buf_or_err.takeError()));
|
||||||
|
|
||||||
|
output_buffer = std::move(*buf_or_err);
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<FileOutputBuffer> output_buffer = std::move(*buf_or_err);
|
|
||||||
u8 *buf = output_buffer->getBufferStart();
|
u8 *buf = output_buffer->getBufferStart();
|
||||||
|
|
||||||
// Fill .symtab and .strtab
|
// Fill .symtab and .strtab
|
||||||
|
5
mold.h
5
mold.h
@ -50,6 +50,11 @@ typedef uint16_t u16;
|
|||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
typedef uint64_t u64;
|
typedef uint64_t u64;
|
||||||
|
|
||||||
|
typedef int8_t i8;
|
||||||
|
typedef int16_t i16;
|
||||||
|
typedef int32_t i32;
|
||||||
|
typedef int64_t i64;
|
||||||
|
|
||||||
using llvm::ArrayRef;
|
using llvm::ArrayRef;
|
||||||
using llvm::ErrorOr;
|
using llvm::ErrorOr;
|
||||||
using llvm::Error;
|
using llvm::Error;
|
||||||
|
@ -72,7 +72,8 @@ void OutputPhdr::construct(std::vector<OutputChunk *> &chunks) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
u32 flags = to_phdr_flags(chunk->shdr.sh_flags);
|
u32 flags = to_phdr_flags(chunk->shdr.sh_flags);
|
||||||
bool this_is_bss = (chunk->shdr.sh_type == SHT_NOBITS);
|
bool this_is_bss =
|
||||||
|
(chunk->shdr.sh_type == SHT_NOBITS && !(chunk->shdr.sh_flags & SHF_TLS));
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
add(PT_LOAD, flags, {chunk});
|
add(PT_LOAD, flags, {chunk});
|
||||||
|
Loading…
Reference in New Issue
Block a user