1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-20 01:18:53 +03:00
This commit is contained in:
Rui Ueyama 2023-01-09 13:34:12 +08:00
parent 7128ee371d
commit d127583c86
4 changed files with 15 additions and 15 deletions

View File

@ -42,6 +42,12 @@ InputFile<E>::InputFile(Context<E> &ctx, MappedFile<Context<E>> *mf)
shstrtab = this->get_string(ctx, shstrtab_idx);
}
template <typename E>
std::span<ElfPhdr<E>> InputFile<E>::get_phdrs() {
ElfEhdr<E> &ehdr = get_ehdr();
return {(ElfPhdr<E> *)(mf->data + ehdr.e_phoff), ehdr.e_phnum};
}
template <typename E>
ElfShdr<E> *InputFile<E>::find_section(i64 type) {
for (ElfShdr<E> &sec : elf_sections)
@ -1556,12 +1562,11 @@ i64 SharedFile<E>::get_alignment(Symbol<E> *sym) {
template <typename E>
bool SharedFile<E>::is_readonly(Context<E> &ctx, Symbol<E> *sym) {
ElfPhdr<E> *phdr = this->get_phdr();
u64 val = sym->esym().st_value;
for (i64 i = 0; i < this->get_ehdr().e_phnum; i++)
if (phdr[i].p_type == PT_LOAD && !(phdr[i].p_flags & PF_W) &&
phdr[i].p_vaddr <= val && val < phdr[i].p_vaddr + phdr[i].p_memsz)
for (ElfPhdr<E> &phdr : this->get_phdrs())
if (phdr.p_type == PT_LOAD && !(phdr.p_flags & PF_W) &&
phdr.p_vaddr <= val && val < phdr.p_vaddr + phdr.p_memsz)
return true;
return false;
}

View File

@ -381,7 +381,7 @@ public:
virtual u8 *get_uncompressed_data() { return nullptr; }
std::string_view name;
ElfShdr<E> shdr = {};
ElfShdr<E> shdr = { .sh_addralign = 1 };
i64 shndx = 0;
// Some synethetic sections add local symbols to the output.
@ -398,9 +398,6 @@ public:
// For --section-order
i64 sect_order = 0;
protected:
Chunk() { shdr.sh_addralign = 1; }
};
// ELF header
@ -1159,7 +1156,7 @@ public:
std::string_view get_string(Context<E> &ctx, i64 idx);
ElfEhdr<E> &get_ehdr() { return *(ElfEhdr<E> *)mf->data; }
ElfPhdr<E> *get_phdr() { return (ElfPhdr<E> *)(mf->data + get_ehdr().e_phoff); }
std::span<ElfPhdr<E>> get_phdrs();
ElfShdr<E> *find_section(i64 type);
@ -1605,7 +1602,7 @@ struct SectionOrder {
u64 value = 0;
};
// Target-specific context clss
// Target-specific context members
template <typename E> struct ContextExtras {};
template <> struct ContextExtras<PPC32> {

View File

@ -174,10 +174,8 @@ u64 get_tp_addr(Context<E> &ctx) {
// TP. RISC-V load/store instructions usually take 12-bits signed
// immediates, so the beginning of TLV ± 2 KiB is accessible with a
// single load/store instruction.
if constexpr (is_riscv<E>)
return phdr->p_vaddr;
unreachable();
assert(is_riscv<E>);
return phdr->p_vaddr;
}
// Returns the address when __tls_get_addr would be called with offset 0.

View File

@ -5,7 +5,7 @@
# musl libc does not support init/fini on ARM
# https://github.com/rui314/mold/issues/951
[ $MACHINE = arm -o $MACHINE = aarch64 ] && ldd --help 2>&1 | grep -q musl && skip
[ $MACHINE = arm -o $MACHINE = aarch64 ] && ldd --help 2>&1 | grep -q musl && skip
cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
void keep();