Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Aug 16, 2024
1 parent ac84d2c commit e30f01f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/arch-arm32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,20 +729,27 @@ Arm32ExidxSection::Arm32ExidxSection(Context<ARM32> &ctx,
this->shdr.sh_type = SHT_ARM_EXIDX;
this->shdr.sh_flags = SHF_ALLOC;
this->shdr.sh_addralign = 4;
this->shdr.sh_size = get_contents(ctx).size();
this->sect_order = osec.sect_order;

for (InputSection<E> *isec : osec.members)
isec->is_alive = false;
}

void Arm32ExidxSection::compute_section_size(Context<E> &ctx) {
output_section.compute_section_size(ctx);
this->shdr.sh_size = output_section.shdr.sh_size;
}

void Arm32ExidxSection::update_shdr(Context<E> &ctx) {
// .ARM.exidx's sh_link should be set to the .text section index.
// Runtime doesn't care about it, but the binutils's strip command does.
if (Chunk<E> *chunk = find_chunk(ctx, ".text"))
this->shdr.sh_link = chunk->shndx;
}

void Arm32ExidxSection::remove_duplicate_entries(Context<E> &ctx) {
this->shdr.sh_size = get_contents(ctx).size();
}

void Arm32ExidxSection::copy_buf(Context<E> &ctx) {
std::vector<u8> contents = get_contents(ctx);
assert(this->shdr.sh_size = contents.size());
Expand Down
15 changes: 11 additions & 4 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ int mold_main(int argc, char **argv) {
// Bin input sections into output sections.
create_output_sections(ctx);

// Convert an .ARM.exidx to a synthetic section.
if constexpr (is_arm32<E>)
create_arm_exidx_section(ctx);

// Handle --section-align options.
if (!ctx.arg.section_align.empty())
apply_section_align(ctx);
Expand Down Expand Up @@ -579,10 +583,6 @@ int mold_main(int argc, char **argv) {
if (ctx.arg.pack_dyn_relocs_relr)
construct_relr(ctx);

// Convert an .ARM.exidx to a synthetic section.
if constexpr (is_arm32<E>)
create_arm_exidx_section(ctx);

// Reserve a space for dynamic symbol strings in .dynstr and sort
// .dynsym contents if necessary. Beyond this point, no symbol will
// be added to .dynsym.
Expand Down Expand Up @@ -628,6 +628,13 @@ int mold_main(int argc, char **argv) {
filesize = set_osec_offsets(ctx);
}

if constexpr (is_arm32<E>) {
if (ctx.extra.exidx) {
ctx.extra.exidx->remove_duplicate_entries(ctx);
filesize = set_osec_offsets(ctx);
}
}

// At this point, memory layout is fixed.

// Set actual addresses to linker-synthesized symbols.
Expand Down
2 changes: 2 additions & 0 deletions src/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,9 @@ void rewrite_endbr(Context<X86_64> &ctx);
class Arm32ExidxSection : public Chunk<ARM32> {
public:
Arm32ExidxSection(Context<ARM32> &ctx, OutputSection<ARM32> &osec);
void compute_section_size(Context<ARM32> &ctx) override;
void update_shdr(Context<ARM32> &ctx) override;
void remove_duplicate_entries(Context<ARM32> &ctx);
void copy_buf(Context<ARM32> &ctx) override;

private:
Expand Down

0 comments on commit e30f01f

Please sign in to comment.