mirror of
https://github.com/rui314/mold.git
synced 2024-12-26 18:02:30 +03:00
temporary
This commit is contained in:
parent
0ae4f93707
commit
0cd77f2861
52
main.cc
52
main.cc
@ -583,43 +583,6 @@ static std::vector<u8> to_u8vector(const std::vector<T> &vec) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::vector<u8>
|
||||
create_dynamic_section(ArrayRef<ObjectFile *> files) {
|
||||
std::vector<u64> vec;
|
||||
|
||||
auto define = [&](u64 tag, u64 val) {
|
||||
vec.push_back(tag);
|
||||
vec.push_back(val);
|
||||
};
|
||||
|
||||
int i = 1;
|
||||
for (ObjectFile *file : files) {
|
||||
if (!file->soname.empty()) {
|
||||
define(DT_NEEDED, i);
|
||||
i += file->soname.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
define(DT_RELA, out::reldyn->shdr.sh_addr);
|
||||
define(DT_RELASZ, out::reldyn->shdr.sh_size);
|
||||
define(DT_RELAENT, sizeof(ELF64LE::Rela));
|
||||
define(DT_JMPREL, out::relplt->shdr.sh_addr);
|
||||
define(DT_PLTRELSZ, out::relplt->shdr.sh_size);
|
||||
define(DT_PLTGOT, out::gotplt->shdr.sh_addr);
|
||||
define(DT_PLTREL, DT_RELA);
|
||||
define(DT_SYMTAB, out::dynsym->shdr.sh_addr);
|
||||
define(DT_SYMENT, sizeof(ELF64LE::Sym));
|
||||
define(DT_STRTAB, out::dynstr->shdr.sh_addr);
|
||||
define(DT_STRSZ, out::dynstr->shdr.sh_size);
|
||||
define(DT_HASH, out::hash->shdr.sh_addr);
|
||||
define(DT_INIT_ARRAY, out::__init_array_start->value);
|
||||
define(DT_INIT_ARRAYSZ, out::__init_array_end->value - out::__init_array_start->value);
|
||||
define(DT_FINI_ARRAY, out::__fini_array_start->value);
|
||||
define(DT_FINI_ARRAYSZ, out::__fini_array_end->value - out::__fini_array_start->value);
|
||||
define(DT_NULL, 0);
|
||||
return to_u8vector(vec);
|
||||
}
|
||||
|
||||
static u64 set_osec_offsets(ArrayRef<OutputChunk *> chunks) {
|
||||
MyTimer t("osec_offset", before_copy_timer);
|
||||
|
||||
@ -801,10 +764,6 @@ static int get_thread_count(InputArgList &args) {
|
||||
return tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism);
|
||||
}
|
||||
|
||||
static void write_vector(u8 *buf, ArrayRef<u8> vec) {
|
||||
memcpy(buf, vec.data(), vec.size());
|
||||
}
|
||||
|
||||
static int parse_filler(opt::InputArgList &args) {
|
||||
auto *arg = args.getLastArg(OPT_filler);
|
||||
if (!arg)
|
||||
@ -883,8 +842,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (!config.is_static) {
|
||||
out::interp = new SpecialSection(".interp", SHT_PROGBITS, SHF_ALLOC);
|
||||
out::dynamic = new SpecialSection(".dynamic", SHT_DYNAMIC, SHF_ALLOC | SHF_WRITE,
|
||||
8, sizeof(ELF64LE::Dyn));
|
||||
out::dynamic = new DynamicSection;
|
||||
out::reldyn = new SpecialSection(".rela.dyn", SHT_RELA, SHF_ALLOC, 8,
|
||||
sizeof(ELF64LE::Rela));
|
||||
out::hash = new HashSection;
|
||||
@ -1025,12 +983,13 @@ int main(int argc, char **argv) {
|
||||
chunks[i]->shndx = shndx++;
|
||||
|
||||
// Initialize synthetic section contents
|
||||
out::files = files;
|
||||
out::chunks = chunks;
|
||||
out::shdr->update_shdr();
|
||||
out::phdr->update_shdr();
|
||||
|
||||
if (out::dynamic)
|
||||
out::dynamic->shdr.sh_size = create_dynamic_section(files).size();
|
||||
out::dynamic->update_shdr();
|
||||
|
||||
if (out::hash)
|
||||
out::hash->update_shdr();
|
||||
@ -1041,9 +1000,6 @@ int main(int argc, char **argv) {
|
||||
if (out::hash && out::dynsym)
|
||||
out::hash->shdr.sh_link = out::dynsym->shndx;
|
||||
|
||||
if (out::dynamic && out::dynstr)
|
||||
out::dynamic->shdr.sh_link = out::dynstr->shndx;
|
||||
|
||||
if (out::reldyn)
|
||||
out::reldyn->shdr.sh_link = out::dynsym->shndx;
|
||||
|
||||
@ -1105,8 +1061,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (out::interp)
|
||||
write_string(buf + out::interp->shdr.sh_offset, config.dynamic_linker);
|
||||
if (out::dynamic)
|
||||
write_vector(buf + out::dynamic->shdr.sh_offset, create_dynamic_section(files));
|
||||
|
||||
// Zero-clear paddings between sections
|
||||
clear_padding(buf, chunks, filesize);
|
||||
|
24
mold.h
24
mold.h
@ -443,6 +443,20 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DynamicSection : public OutputChunk {
|
||||
public:
|
||||
DynamicSection() : OutputChunk(SYNTHETIC) {
|
||||
this->name = ".dynamic";
|
||||
shdr.sh_type = llvm::ELF::SHT_DYNAMIC;
|
||||
shdr.sh_flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE;
|
||||
shdr.sh_addralign = 8;
|
||||
shdr.sh_entsize = sizeof(ELF64LE::Dyn);
|
||||
}
|
||||
|
||||
void update_shdr() override;
|
||||
void copy_to(u8 *buf) override;
|
||||
};
|
||||
|
||||
class SymtabSection : public OutputChunk {
|
||||
public:
|
||||
SymtabSection(StringRef name, u32 type, u64 flags) : OutputChunk(SYNTHETIC) {
|
||||
@ -522,7 +536,8 @@ bool is_c_identifier(StringRef name);
|
||||
namespace out {
|
||||
using namespace llvm::ELF;
|
||||
|
||||
inline std::vector<OutputChunk *> chunks;
|
||||
inline ArrayRef<ObjectFile *> files;
|
||||
inline ArrayRef<OutputChunk *> chunks;
|
||||
|
||||
inline OutputEhdr *ehdr;
|
||||
inline OutputShdr *shdr;
|
||||
@ -532,7 +547,7 @@ inline SpecialSection *got;
|
||||
inline GotPltSection *gotplt;
|
||||
inline SpecialSection *relplt;
|
||||
inline SpecialSection *reldyn;
|
||||
inline SpecialSection *dynamic;
|
||||
inline DynamicSection *dynamic;
|
||||
inline StrtabSection *strtab;
|
||||
inline StrtabSection *dynstr;
|
||||
inline HashSection *hash;
|
||||
@ -701,6 +716,11 @@ inline void write_string(u8 *buf, StringRef str) {
|
||||
buf[str.size()] = '\0';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void write_vector(u8 *buf, const std::vector<T> &vec) {
|
||||
memcpy(buf, vec.data(), vec.size() * sizeof(T));
|
||||
}
|
||||
|
||||
//
|
||||
// perf.cc
|
||||
//
|
||||
|
@ -136,9 +136,52 @@ void OutputPhdr::update_shdr() {
|
||||
}
|
||||
|
||||
void OutputPhdr::copy_to(u8 *buf) {
|
||||
auto *ptr = (ELF64LE::Phdr *)(buf + shdr.sh_offset);
|
||||
for (ELF64LE::Phdr &phdr : create_phdr())
|
||||
*ptr++ = phdr;
|
||||
write_vector(buf + shdr.sh_offset, create_phdr());
|
||||
}
|
||||
|
||||
static std::vector<u64> create_dynamic_section() {
|
||||
std::vector<u64> vec;
|
||||
|
||||
auto define = [&](u64 tag, u64 val) {
|
||||
vec.push_back(tag);
|
||||
vec.push_back(val);
|
||||
};
|
||||
|
||||
int i = 1;
|
||||
for (ObjectFile *file : out::files) {
|
||||
if (!file->soname.empty()) {
|
||||
define(DT_NEEDED, i);
|
||||
i += file->soname.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
define(DT_RELA, out::reldyn->shdr.sh_addr);
|
||||
define(DT_RELASZ, out::reldyn->shdr.sh_size);
|
||||
define(DT_RELAENT, sizeof(ELF64LE::Rela));
|
||||
define(DT_JMPREL, out::relplt->shdr.sh_addr);
|
||||
define(DT_PLTRELSZ, out::relplt->shdr.sh_size);
|
||||
define(DT_PLTGOT, out::gotplt->shdr.sh_addr);
|
||||
define(DT_PLTREL, DT_RELA);
|
||||
define(DT_SYMTAB, out::dynsym->shdr.sh_addr);
|
||||
define(DT_SYMENT, sizeof(ELF64LE::Sym));
|
||||
define(DT_STRTAB, out::dynstr->shdr.sh_addr);
|
||||
define(DT_STRSZ, out::dynstr->shdr.sh_size);
|
||||
define(DT_HASH, out::hash->shdr.sh_addr);
|
||||
define(DT_INIT_ARRAY, out::__init_array_start->value);
|
||||
define(DT_INIT_ARRAYSZ, out::__init_array_end->value - out::__init_array_start->value);
|
||||
define(DT_FINI_ARRAY, out::__fini_array_start->value);
|
||||
define(DT_FINI_ARRAYSZ, out::__fini_array_end->value - out::__fini_array_start->value);
|
||||
define(DT_NULL, 0);
|
||||
return vec;
|
||||
}
|
||||
|
||||
void DynamicSection::update_shdr() {
|
||||
shdr.sh_size = create_dynamic_section().size() * 8;
|
||||
shdr.sh_link = out::dynstr->shndx;
|
||||
}
|
||||
|
||||
void DynamicSection::copy_to(u8 *buf) {
|
||||
write_vector(buf + shdr.sh_offset, create_dynamic_section());
|
||||
}
|
||||
|
||||
static StringRef get_output_name(StringRef name) {
|
||||
|
Loading…
Reference in New Issue
Block a user