1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-26 09:51:53 +03:00
This commit is contained in:
Rui Ueyama 2021-03-30 14:57:38 +09:00
parent 36173c0227
commit 5dd05216be
14 changed files with 105 additions and 160 deletions

View File

@ -82,9 +82,9 @@ read_fat_archive_members(Context<E> &ctx, MemoryMappedFile<E> *mb) {
}
template
std::vector<MemoryMappedFile<ELF64LE> *>
read_fat_archive_members(Context<ELF64LE> &ctx, MemoryMappedFile<ELF64LE> *mb);
std::vector<MemoryMappedFile<X86_64> *>
read_fat_archive_members(Context<X86_64> &ctx, MemoryMappedFile<X86_64> *mb);
template
std::vector<MemoryMappedFile<ELF64LE> *>
read_thin_archive_members(Context<ELF64LE> &ctx, MemoryMappedFile<ELF64LE> *mb);
std::vector<MemoryMappedFile<X86_64> *>
read_thin_archive_members(Context<X86_64> &ctx, MemoryMappedFile<X86_64> *mb);

View File

@ -491,13 +491,13 @@ void parse_nonpositional_args(Context<E> &ctx,
template
std::vector<std::string_view>
expand_response_files(Context<ELF64LE> &ctx, char **argv);
expand_response_files(Context<X86_64> &ctx, char **argv);
template
bool read_arg(Context<ELF64LE> &ctx, std::span<std::string_view> &args,
bool read_arg(Context<X86_64> &ctx, std::span<std::string_view> &args,
std::string_view &arg,
std::string name);
template
void parse_nonpositional_args(Context<ELF64LE> &ctx,
void parse_nonpositional_args(Context<X86_64> &ctx,
std::vector<std::string_view> &remaining);

149
elf.h
View File

@ -279,13 +279,7 @@ static constexpr u32 DW_EH_PE_datarel = 0x30;
static constexpr u32 DW_EH_PE_funcrel = 0x40;
static constexpr u32 DW_EH_PE_aligned = 0x50;
struct ELF64LE {};
struct ELF32LE {};
template <typename E> struct ElfSym;
template <>
struct ElfSym<ELF64LE> {
struct Elf64Sym {
bool is_defined() const { return !is_undef(); }
bool is_undef() const { return st_shndx == SHN_UNDEF; }
bool is_abs() const { return st_shndx == SHN_ABS; }
@ -300,8 +294,7 @@ struct ElfSym<ELF64LE> {
u64 st_size;
};
template <>
struct ElfSym<ELF32LE> {
struct Elf32Sym {
bool is_defined() const { return !is_undef(); }
bool is_undef() const { return st_shndx == SHN_UNDEF; }
bool is_abs() const { return st_shndx == SHN_ABS; }
@ -316,10 +309,7 @@ struct ElfSym<ELF32LE> {
u16 st_shndx;
};
template <typename E> struct ElfShdr;
template<>
struct ElfShdr<ELF64LE> {
struct Elf64Shdr {
u32 sh_name;
u32 sh_type;
u64 sh_flags;
@ -332,8 +322,7 @@ struct ElfShdr<ELF64LE> {
u64 sh_entsize;
};
template<>
struct ElfShdr<ELF32LE> {
struct Elf32Shdr {
u32 sh_name;
u32 sh_type;
u32 sh_flags;
@ -346,10 +335,7 @@ struct ElfShdr<ELF32LE> {
u32 sh_entsize;
};
template <typename E> struct ElfEhdr;
template <>
struct ElfEhdr<ELF64LE> {
struct Elf64Ehdr {
u8 e_ident[16];
u16 e_type;
u16 e_machine;
@ -366,8 +352,7 @@ struct ElfEhdr<ELF64LE> {
u16 e_shstrndx;
};
template <>
struct ElfEhdr<ELF32LE> {
struct Elf32Ehdr {
u8 e_ident[16];
u16 e_type;
u16 e_machine;
@ -384,10 +369,7 @@ struct ElfEhdr<ELF32LE> {
u16 e_shstrndx;
};
template <typename E> struct ElfPhdr;
template <>
struct ElfPhdr<ELF64LE> {
struct Elf64Phdr {
u32 p_type;
u32 p_flags;
u64 p_offset;
@ -398,8 +380,7 @@ struct ElfPhdr<ELF64LE> {
u64 p_align;
};
template <>
struct ElfPhdr<ELF32LE> {
struct Elf32Phdr {
u32 p_type;
u32 p_offset;
u32 p_vaddr;
@ -410,58 +391,43 @@ struct ElfPhdr<ELF32LE> {
u32 p_align;
};
template <typename E> struct ElfRel;
template <>
struct ElfRel<ELF64LE> {
struct Elf64Rel {
u64 r_offset;
u32 r_type;
u32 r_sym;
};
template <>
struct ElfRel<ELF32LE> {
struct Elf32Rel {
u32 r_offset;
u32 r_type : 8;
u32 r_sym : 24;
};
template <typename E> struct ElfRela;
template <>
struct ElfRela<ELF64LE> {
struct Elf64Rela {
u64 r_offset;
u32 r_type;
u32 r_sym;
i64 r_addend;
};
template <>
struct ElfRela<ELF32LE> {
struct Elf32Rela {
u32 r_offset;
u32 r_type : 8;
u32 r_sym : 24;
i32 r_addend;
};
template <typename E> struct ElfDyn;
template <>
struct ElfDyn<ELF64LE> {
struct Elf64Dyn {
u64 d_tag;
u64 d_val;
};
template <>
struct ElfDyn<ELF32LE> {
struct Elf32Dyn {
u32 d_tag;
u32 d_val;
};
template <typename E> struct ElfVerneed;
template <>
struct ElfVerneed<ELF64LE> {
struct Elf64Verneed {
u16 vn_version;
u16 vn_cnt;
u32 vn_file;
@ -469,19 +435,7 @@ struct ElfVerneed<ELF64LE> {
u32 vn_next;
};
template <>
struct ElfVerneed<ELF32LE> {
u16 vn_version;
u16 vn_cnt;
u32 vn_file;
u32 vn_aux;
u32 vn_next;
};
template <typename E> struct ElfVernaux;
template <>
struct ElfVernaux<ELF64LE> {
struct Elf64Vernaux {
u32 vna_hash;
u16 vna_flags;
u16 vna_other;
@ -489,19 +443,7 @@ struct ElfVernaux<ELF64LE> {
u32 vna_next;
};
template <>
struct ElfVernaux<ELF32LE> {
u32 vna_hash;
u16 vna_flags;
u16 vna_other;
u32 vna_name;
u32 vna_next;
};
template <typename E> struct ElfVerdef;
template <>
struct ElfVerdef<ELF64LE> {
struct Elf64Verdef {
u16 vd_version;
u16 vd_flags;
u16 vd_ndx;
@ -511,44 +453,47 @@ struct ElfVerdef<ELF64LE> {
u32 vd_next;
};
template <>
struct ElfVerdef<ELF32LE> {
u16 vd_version;
u16 vd_flags;
u16 vd_ndx;
u16 vd_cnt;
u32 vd_hash;
u32 vd_aux;
u32 vd_next;
};
template <typename E> struct ElfVerdaux;
template <>
struct ElfVerdaux<ELF64LE> {
struct Elf64Verdaux {
u32 vda_name;
u32 vda_next;
};
template <>
struct ElfVerdaux<ELF32LE> {
u32 vda_name;
u32 vda_next;
};
template <typename E> struct ElfChdr;
template <>
struct ElfChdr<ELF64LE> {
struct Elf64Chdr {
u32 ch_type;
u32 ch_reserved;
u64 ch_size;
u64 ch_addralign;
};
template <>
struct ElfChdr<ELF32LE> {
struct Elf32Chdr {
u32 ch_type;
u32 ch_size;
u32 ch_addralign;
};
template <typename E> struct ElfSym;
template <typename E> struct ElfShdr;
template <typename E> struct ElfEhdr;
template <typename E> struct ElfPhdr;
template <typename E> struct ElfRel;
template <typename E> struct ElfRela;
template <typename E> struct ElfDyn;
template <typename E> struct ElfVerneed;
template <typename E> struct ElfVernaux;
template <typename E> struct ElfVerdef;
template <typename E> struct ElfVerdaux;
template <typename E> struct ElfChdr;
struct X86_64 {};
template <> struct ElfSym<X86_64> : public Elf64Sym {};
template <> struct ElfShdr<X86_64> : public Elf64Shdr {};
template <> struct ElfEhdr<X86_64> : public Elf64Ehdr {};
template <> struct ElfPhdr<X86_64> : public Elf64Phdr {};
template <> struct ElfRela<X86_64> : public Elf64Rela {};
template <> struct ElfDyn<X86_64> : public Elf64Dyn {};
template <> struct ElfVerneed<X86_64> : public Elf64Verneed {};
template <> struct ElfVernaux<X86_64> : public Elf64Vernaux {};
template <> struct ElfVerdef<X86_64> : public Elf64Verdef {};
template <> struct ElfVerdaux<X86_64> : public Elf64Verdaux {};
template <> struct ElfChdr<X86_64> : public Elf64Chdr {};

View File

@ -184,4 +184,4 @@ void gc_sections(Context<E> &ctx) {
sweep(ctx);
}
template void gc_sections(Context<ELF64LE> &ctx);
template void gc_sections(Context<X86_64> &ctx);

2
icf.cc
View File

@ -563,4 +563,4 @@ void icf_sections(Context<E> &ctx) {
}
}
template void icf_sections(Context<ELF64LE> &ctx);
template void icf_sections(Context<X86_64> &ctx);

View File

@ -790,4 +790,4 @@ void InputSection<E>::kill() {
}
}
template class InputSection<ELF64LE>;
template class InputSection<X86_64>;

View File

@ -319,10 +319,10 @@ void parse_dynamic_list(Context<E> &ctx, std::string path) {
}
template
void parse_linker_script(Context<ELF64LE> &ctx, MemoryMappedFile<ELF64LE> *mb);
void parse_linker_script(Context<X86_64> &ctx, MemoryMappedFile<X86_64> *mb);
template
void parse_version_script(Context<ELF64LE> &ctx, std::string path);
void parse_version_script(Context<X86_64> &ctx, std::string path);
template
void parse_dynamic_list(Context<ELF64LE> &ctx, std::string path);
void parse_dynamic_list(Context<X86_64> &ctx, std::string path);

View File

@ -1443,7 +1443,7 @@ int do_main(int argc, char **argv) {
}
int main(int argc, char **argv) {
return do_main<ELF64LE>(argc, argv);
return do_main<X86_64>(argc, argv);
}
template void read_file(Context<ELF64LE> &ctx, MemoryMappedFile<ELF64LE> *mb);
template void read_file(Context<X86_64> &ctx, MemoryMappedFile<X86_64> *mb);

View File

@ -83,4 +83,4 @@ void print_map(Context<E> &ctx) {
file->close();
}
template void print_map(Context<ELF64LE> &ctx);
template void print_map(Context<X86_64> &ctx);

View File

@ -1241,9 +1241,9 @@ bool SharedFile<E>::is_readonly(Context<E> &ctx, Symbol<E> *sym) {
return false;
}
template class MemoryMappedFile<ELF64LE>;
template class ObjectFile<ELF64LE>;
template class SharedFile<ELF64LE>;
template class MemoryMappedFile<X86_64>;
template class ObjectFile<X86_64>;
template class SharedFile<X86_64>;
template
std::ostream &operator<<(std::ostream &out, const InputFile<ELF64LE> &file);
std::ostream &operator<<(std::ostream &out, const InputFile<X86_64> &file);

View File

@ -1479,35 +1479,35 @@ void BuildIdSection<E>::write_buildid(Context<E> &ctx, i64 filesize) {
unreachable(ctx);
}
template class OutputChunk<ELF64LE>;
template class OutputEhdr<ELF64LE>;
template class OutputShdr<ELF64LE>;
template class OutputPhdr<ELF64LE>;
template class InterpSection<ELF64LE>;
template class OutputSection<ELF64LE>;
template class GotSection<ELF64LE>;
template class GotPltSection<ELF64LE>;
template class PltSection<ELF64LE>;
template class PltGotSection<ELF64LE>;
template class RelPltSection<ELF64LE>;
template class RelDynSection<ELF64LE>;
template class StrtabSection<ELF64LE>;
template class ShstrtabSection<ELF64LE>;
template class DynstrSection<ELF64LE>;
template class DynamicSection<ELF64LE>;
template class SymtabSection<ELF64LE>;
template class DynsymSection<ELF64LE>;
template class HashSection<ELF64LE>;
template class GnuHashSection<ELF64LE>;
template class MergedSection<ELF64LE>;
template class EhFrameSection<ELF64LE>;
template class EhFrameHdrSection<ELF64LE>;
template class DynbssSection<ELF64LE>;
template class VersymSection<ELF64LE>;
template class VerneedSection<ELF64LE>;
template class VerdefSection<ELF64LE>;
template class BuildIdSection<ELF64LE>;
template class OutputChunk<X86_64>;
template class OutputEhdr<X86_64>;
template class OutputShdr<X86_64>;
template class OutputPhdr<X86_64>;
template class InterpSection<X86_64>;
template class OutputSection<X86_64>;
template class GotSection<X86_64>;
template class GotPltSection<X86_64>;
template class PltSection<X86_64>;
template class PltGotSection<X86_64>;
template class RelPltSection<X86_64>;
template class RelDynSection<X86_64>;
template class StrtabSection<X86_64>;
template class ShstrtabSection<X86_64>;
template class DynstrSection<X86_64>;
template class DynamicSection<X86_64>;
template class SymtabSection<X86_64>;
template class DynsymSection<X86_64>;
template class HashSection<X86_64>;
template class GnuHashSection<X86_64>;
template class MergedSection<X86_64>;
template class EhFrameSection<X86_64>;
template class EhFrameHdrSection<X86_64>;
template class DynbssSection<X86_64>;
template class VersymSection<X86_64>;
template class VerneedSection<X86_64>;
template class VerdefSection<X86_64>;
template class BuildIdSection<X86_64>;
template i64 BuildId::size(Context<ELF64LE> &ctx) const;
template bool is_relro(Context<ELF64LE> &ctx, OutputChunk<ELF64LE> *chunk);
template std::vector<ElfPhdr<ELF64LE>> create_phdr<ELF64LE>(Context<ELF64LE> &ctx);
template i64 BuildId::size(Context<X86_64> &ctx) const;
template bool is_relro(Context<X86_64> &ctx, OutputChunk<X86_64> *chunk);
template std::vector<ElfPhdr<X86_64>> create_phdr<X86_64>(Context<X86_64> &ctx);

View File

@ -105,5 +105,5 @@ OutputFile<E>::open(Context<E> &ctx, std::string path, u64 filesize) {
}
template
OutputFile<ELF64LE> *
OutputFile<ELF64LE>::open(Context<ELF64LE> &ctx, std::string path, u64 filesize);
OutputFile<X86_64> *
OutputFile<X86_64>::open(Context<X86_64> &ctx, std::string path, u64 filesize);

View File

@ -253,12 +253,12 @@ void process_run_subcommand(Context<E> &ctx, int argc, char **argv) {
}
template
bool resume_daemon(Context<ELF64LE> &ctx, char **argv, i64 *code);
bool resume_daemon(Context<X86_64> &ctx, char **argv, i64 *code);
template
void daemonize(Context<ELF64LE> &ctx, char **argv,
void daemonize(Context<X86_64> &ctx, char **argv,
std::function<void()> *wait_for_client,
std::function<void()> *on_complete);
template
void process_run_subcommand(Context<ELF64LE> &ctx, int argc, char **argv);
void process_run_subcommand(Context<X86_64> &ctx, int argc, char **argv);

View File

@ -34,7 +34,7 @@ std::ostream &operator<<(std::ostream &out, const Symbol<E> &sym) {
return out;
}
template class Symbol<ELF64LE>;
template class Symbol<X86_64>;
template
std::ostream &operator<<(std::ostream &out, const Symbol<ELF64LE> &sym);
std::ostream &operator<<(std::ostream &out, const Symbol<X86_64> &sym);