mirror of
https://github.com/rui314/mold.git
synced 2024-09-23 02:49:12 +03:00
36 lines
1.0 KiB
C++
36 lines
1.0 KiB
C++
#include "chibild.h"
|
|
|
|
static OutputSection *get_output_section(StringRef name) {
|
|
static OutputSection sections[] = {
|
|
{".text"}, {".data"}, {".data.rel.ro"}, {".rodata"}, {".bss"}, {".bss.rel.ro"},
|
|
{".ctors"}, {".dtors"}, {".init_array"}, {".fini_array"}, {".tbss"}, {".tdata"},
|
|
};
|
|
|
|
for (OutputSection &osec : sections) {
|
|
if (!name.startswith(osec.name))
|
|
continue;
|
|
if (name.size() == osec.name.size())
|
|
return &osec;
|
|
if (name.size() > osec.name.size() && name[osec.name.size()] == '.')
|
|
return &osec;
|
|
};
|
|
|
|
static ConcurrentMap<OutputSection> map;
|
|
return map.insert(name, OutputSection(name));
|
|
}
|
|
|
|
InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr *hdr, StringRef name)
|
|
: file(file), hdr(hdr) {
|
|
this->name = name;
|
|
this->output_section = get_output_section(name);
|
|
}
|
|
|
|
uint64_t InputSection::get_size() const {
|
|
return hdr->sh_size;
|
|
}
|
|
|
|
void InputSection::copy_to(uint8_t *buf) {
|
|
ArrayRef<uint8_t> data = check(file->obj.getSectionContents(*hdr));
|
|
memcpy(buf + offset, &data[0], data.size());
|
|
}
|