1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-13 09:39:13 +03:00
This commit is contained in:
Rui Ueyama 2021-04-12 20:18:43 +09:00
parent 0161d126b8
commit 33c7719838
5 changed files with 23 additions and 16 deletions

View File

@ -15,10 +15,10 @@ static bool is_init_fini(const InputSection<E> &isec) {
return isec.shdr.sh_type == SHT_INIT_ARRAY ||
isec.shdr.sh_type == SHT_FINI_ARRAY ||
isec.shdr.sh_type == SHT_PREINIT_ARRAY ||
isec.name.starts_with(".ctors") ||
isec.name.starts_with(".dtors") ||
isec.name.starts_with(".init") ||
isec.name.starts_with(".fini");
isec.name().starts_with(".ctors") ||
isec.name().starts_with(".dtors") ||
isec.name().starts_with(".init") ||
isec.name().starts_with(".fini");
}
template <typename E>

2
icf.cc
View File

@ -101,7 +101,7 @@ static void uniquify_cies(Context<E> &ctx) {
template <typename E>
static bool is_eligible(InputSection<E> &isec) {
const ElfShdr<E> &shdr = isec.shdr;
std::string_view name = isec.name;
std::string_view name = isec.name();
bool is_alloc = (shdr.sh_flags & SHF_ALLOC);
bool is_executable = (shdr.sh_flags & SHF_EXECINSTR);

View File

@ -18,9 +18,9 @@ void InputSection<E>::do_uncompress(Context<E> &ctx, std::string_view data,
unsigned long size2 = size;
if (uncompress(buf->data(), &size2, (u8 *)&data[0], data.size()) != Z_OK)
Fatal(ctx) << file << ": " << name << ": uncompress failed";
Fatal(ctx) << file << ": " << name() << ": uncompress failed";
if (size != size2)
Fatal(ctx) << file << ": " << name << ": uncompress: invalid size";
Fatal(ctx) << file << ": " << name() << ": uncompress: invalid size";
contents = {(char *)buf->data(), size};
}
@ -29,7 +29,7 @@ template <typename E>
void InputSection<E>::uncompress_old_style(Context<E> &ctx) {
std::string_view data = file.get_string(ctx, shdr);
if (!data.starts_with("ZLIB") || data.size() <= 12)
Fatal(ctx) << file << ": " << name << ": corrupted compressed section";
Fatal(ctx) << file << ": " << name() << ": corrupted compressed section";
u64 size = read64be((u8 *)&data[4]);
do_uncompress(ctx, data.substr(12), size);
}
@ -40,11 +40,11 @@ void InputSection<E>::uncompress_new_style(Context<E> &ctx) {
// New-style compressed section
std::string_view data = file.get_string(ctx, shdr);
if (data.size() < sizeof(ElfChdr<E>))
Fatal(ctx) << file << ": " << name << ": corrupted compressed section";
Fatal(ctx) << file << ": " << name() << ": corrupted compressed section";
ElfChdr<E> &hdr = *(ElfChdr<E> *)&data[0];
if (hdr.ch_type != ELFCOMPRESS_ZLIB)
Fatal(ctx) << file << ": " << name << ": unsupported compression type";
Fatal(ctx) << file << ": " << name() << ": unsupported compression type";
do_uncompress(ctx, data.substr(sizeof(ElfChdr<E>)), hdr.ch_size);
}

13
mold.h
View File

@ -225,7 +225,8 @@ class InputSection {
public:
InputSection(Context<E> &ctx, ObjectFile<E> &file, const ElfShdr<E> &shdr,
std::string_view name, i64 section_idx)
: file(file), shdr(shdr), name(name), section_idx(section_idx) {
: file(file), shdr(shdr), nameptr(name.data()), namelen(name.size()),
section_idx(section_idx) {
if (name.starts_with(".zdebug"))
uncompress_old_style(ctx);
else if (shdr.sh_flags & SHF_COMPRESSED)
@ -244,6 +245,10 @@ public:
void apply_reloc_nonalloc(Context<E> &ctx, u8 *base);
inline void kill();
inline std::string_view name() const {
return {nameptr, (size_t)namelen};
}
inline i64 get_priority() const;
inline u64 get_addr() const;
inline i64 get_addend(const ElfRel<E> &rel) const;
@ -253,13 +258,15 @@ public:
const ElfShdr<E> &shdr;
OutputSection<E> *output_section = nullptr;
std::string_view name;
std::string_view contents;
std::unique_ptr<SectionFragmentRef<E>[]> rel_fragments;
std::unique_ptr<u8[]> rel_types;
std::span<FdeRecord<E>> fdes;
const char *nameptr = nullptr;
i32 namelen = 0;
u32 offset = -1;
u32 section_idx = -1;
u32 relsec_idx = -1;
@ -1800,7 +1807,7 @@ std::ostream &operator<<(std::ostream &out, const InputFile<E> &file);
template <typename E>
inline std::ostream &
operator<<(std::ostream &out, const InputSection<E> &isec) {
out << isec.file << ":(" << isec.name << ")";
out << isec.file << ":(" << isec.name() << ")";
return out;
}

View File

@ -242,7 +242,7 @@ template <typename E>
void ObjectFile<E>::initialize_ehframe_sections(Context<E> &ctx) {
for (i64 i = 0; i < sections.size(); i++) {
std::unique_ptr<InputSection<E>> &isec = sections[i];
if (isec && isec->is_alive && isec->name == ".eh_frame") {
if (isec && isec->is_alive && isec->name() == ".eh_frame") {
read_ehframe(ctx, *isec);
isec->is_ehframe = true;
isec->is_alive = false;
@ -427,7 +427,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
if (name.empty() && esym.st_type == STT_SECTION)
if (InputSection<E> *sec = get_section(esym))
name = sec->name;
name = sec->name();
Symbol<E> &sym = this->local_syms[i];
new (&sym) Symbol<E>(name);
@ -519,7 +519,7 @@ split_section(Context<E> &ctx, InputSection<E> &sec) {
MergeableSection<E> rec;
MergedSection<E> *parent =
MergedSection<E>::get_instance(ctx, sec.name, sec.shdr.sh_type,
MergedSection<E>::get_instance(ctx, sec.name(), sec.shdr.sh_type,
sec.shdr.sh_flags);
std::string_view data = sec.contents;