mirror of
https://github.com/rui314/mold.git
synced 2024-12-27 10:23:41 +03:00
temporary
This commit is contained in:
parent
da438af6ef
commit
5e24b5048e
62
main.cc
62
main.cc
@ -315,65 +315,13 @@ int main(int argc, char **argv) {
|
||||
{
|
||||
MyTimer t("file_offset", before_copy);
|
||||
|
||||
std::vector<ArrayRef<OutputChunk *>> slices;
|
||||
|
||||
int i = 0;
|
||||
while (i < output_chunks.size() && !output_chunks[i]->is_bss()) {
|
||||
int j = i + 1;
|
||||
while (j < output_chunks.size() && !output_chunks[j]->starts_new_ptload &&
|
||||
!output_chunks[j]->is_bss())
|
||||
j++;
|
||||
|
||||
slices.push_back(ArrayRef(output_chunks).slice(i, j - i));
|
||||
i = j;
|
||||
}
|
||||
|
||||
if (i != output_chunks.size())
|
||||
slices.push_back(ArrayRef(output_chunks).slice(i));
|
||||
|
||||
for (ArrayRef<OutputChunk *> slice : slices) {
|
||||
uint64_t vaddr = 0;
|
||||
uint64_t fileoff = 0;
|
||||
|
||||
for (OutputChunk *chunk : slice) {
|
||||
vaddr = align_to(vaddr, chunk->shdr.sh_addralign);
|
||||
if (!chunk->is_bss())
|
||||
fileoff = align_to(fileoff, chunk->shdr.sh_addralign);
|
||||
|
||||
chunk->set_offset(vaddr, fileoff);
|
||||
|
||||
vaddr += chunk->get_filesz();
|
||||
if (!chunk->is_bss())
|
||||
fileoff += chunk->get_filesz();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t vaddr = 0x200000;
|
||||
uint64_t fileoff = 0;
|
||||
|
||||
for (ArrayRef<OutputChunk *> slice : slices) {
|
||||
vaddr = align_to(vaddr, PAGE_SIZE);
|
||||
fileoff = align_to(fileoff, PAGE_SIZE);
|
||||
|
||||
for (OutputChunk *chunk : slice) {
|
||||
chunk->shdr.sh_addr += vaddr;
|
||||
chunk->shdr.sh_offset += fileoff;
|
||||
}
|
||||
|
||||
OutputChunk *last = slice.back();
|
||||
vaddr = last->shdr.sh_addr + last->shdr.sh_size;
|
||||
|
||||
if (last->is_bss())
|
||||
fileoff = last->shdr.sh_offset;
|
||||
else
|
||||
fileoff = last->shdr.sh_offset + last->get_filesz();
|
||||
}
|
||||
|
||||
for (OutputChunk *chunk : output_chunks) {
|
||||
llvm::outs() << chunk->name
|
||||
<< " vaddr=" << chunk->shdr.sh_addr
|
||||
<< " offset=" << chunk->shdr.sh_offset
|
||||
<< "\n";
|
||||
if (!chunk->is_bss())
|
||||
fileoff = align_to(fileoff, chunk->shdr.sh_addralign);
|
||||
chunk->set_offset(fileoff);
|
||||
if (!chunk->is_bss())
|
||||
fileoff = chunk->get_filesz();
|
||||
}
|
||||
}
|
||||
|
||||
|
11
mold.h
11
mold.h
@ -222,8 +222,7 @@ public:
|
||||
virtual void copy_to(uint8_t *buf) = 0;
|
||||
virtual void relocate(uint8_t *buf) {}
|
||||
|
||||
virtual void set_offset(uint64_t vaddr, uint64_t fileoff) {
|
||||
shdr.sh_addr = vaddr;
|
||||
virtual void set_offset(uint64_t fileoff) {
|
||||
shdr.sh_offset = fileoff;
|
||||
}
|
||||
|
||||
@ -304,11 +303,13 @@ public:
|
||||
}
|
||||
|
||||
void copy_to(uint8_t *buf) override {
|
||||
for_each(chunks, [&](InputSection *isec) { isec->copy_to(buf); });
|
||||
if (!is_bss())
|
||||
for_each(chunks, [&](InputSection *isec) { isec->copy_to(buf); });
|
||||
}
|
||||
|
||||
void relocate(uint8_t *buf) override {
|
||||
for_each(chunks, [&](InputSection *isec) { isec->relocate(buf); });
|
||||
if (!is_bss())
|
||||
for_each(chunks, [&](InputSection *isec) { isec->relocate(buf); });
|
||||
}
|
||||
|
||||
uint64_t get_filesz() const override {
|
||||
@ -317,7 +318,7 @@ public:
|
||||
return shdr.sh_size;
|
||||
}
|
||||
|
||||
void set_offset(uint64_t vaddr, uint64_t fileoff) override;
|
||||
void set_offset(uint64_t fileoff) override;
|
||||
void set_alignment(uint32_t align) { shdr.sh_addralign = align; }
|
||||
|
||||
std::vector<InputSection *> chunks;
|
||||
|
@ -122,20 +122,18 @@ void OutputPhdr::copy_to(uint8_t *buf) {
|
||||
*p++ = ent.phdr;
|
||||
}
|
||||
|
||||
void OutputSection::set_offset(uint64_t vaddr, uint64_t fileoff) {
|
||||
shdr.sh_addr = vaddr;
|
||||
void OutputSection::set_offset(uint64_t fileoff) {
|
||||
shdr.sh_offset = fileoff;
|
||||
|
||||
if ((shdr.sh_flags & SHF_ALLOC) && !(shdr.sh_type & SHT_NOBITS))
|
||||
assert(vaddr == fileoff);
|
||||
if (!is_bss()) {
|
||||
uint64_t off = 0;
|
||||
|
||||
for (InputSection *isec : chunks) {
|
||||
vaddr = align_to(vaddr, isec->shdr.sh_addralign);
|
||||
isec->offset = vaddr;
|
||||
vaddr += isec->shdr.sh_size;
|
||||
for (InputSection *isec : chunks) {
|
||||
off = align_to(off, isec->shdr.sh_addralign);
|
||||
isec->offset = off;
|
||||
off += isec->shdr.sh_size;
|
||||
}
|
||||
}
|
||||
|
||||
shdr.sh_size = vaddr - shdr.sh_addr;
|
||||
}
|
||||
|
||||
static StringRef get_output_name(StringRef name) {
|
||||
|
Loading…
Reference in New Issue
Block a user