Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Apr 12, 2021
1 parent 0161d12 commit 33c7719
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
8 changes: 4 additions & 4 deletions gc_sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion icf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions input_sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

Expand All @@ -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);
}
Expand All @@ -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);
}

Expand Down
13 changes: 10 additions & 3 deletions mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -244,6 +245,10 @@ class InputSection {
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;
Expand All @@ -253,13 +258,15 @@ class InputSection {
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;
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions object_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 33c7719

Please sign in to comment.