diff --git a/CMakeLists.txt b/CMakeLists.txt index ff662cc4d5..9229f9a208 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,7 +252,7 @@ if(NOT APPLE AND NOT WIN32) # Remove the default `lib` prefix set_target_properties(mold-wrapper PROPERTIES PREFIX "") target_link_libraries(mold-wrapper PRIVATE ${CMAKE_DL_LIBS}) - target_sources(mold-wrapper PRIVATE elf/mold-wrapper.c) + target_sources(mold-wrapper PRIVATE src/mold-wrapper.c) endif() # If atomics doesn't work by default, add -latomic. @@ -284,15 +284,15 @@ add_custom_target(git_hash COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR} -DOUTPUT_FILE=${CMAKE_BINARY_DIR}/git-hash.cc - -P ${CMAKE_SOURCE_DIR}/common/update-git-hash.cmake - DEPENDS common/update-git-hash.cmake + -P ${CMAKE_SOURCE_DIR}/lib/update-git-hash.cmake + DEPENDS lib/update-git-hash.cmake BYPRODUCTS git-hash.cc VERBATIM) add_dependencies(mold git_hash) # Create config.h file -configure_file(common/config.h.in config.h) +configure_file(lib/config.h.in config.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) # Almost all functions are template in mold which take a target type @@ -308,35 +308,35 @@ list(APPEND MOLD_ELF_TARGETS S390X SPARC64 M68K SH4 ALPHA LOONGARCH32 LOONGARCH64) list(APPEND MOLD_ELF_TEMPLATE_FILES - elf/arch-loongarch.cc - elf/arch-riscv.cc - elf/cmdline.cc - elf/gc-sections.cc - elf/gdb-index.cc - elf/icf.cc - elf/input-files.cc - elf/input-sections.cc - elf/linker-script.cc - elf/main.cc - elf/mapfile.cc - elf/output-chunks.cc - elf/passes.cc - elf/relocatable.cc - elf/shrink-sections.cc - elf/thunks.cc - elf/tls.cc + src/arch-loongarch.cc + src/arch-riscv.cc + src/cmdline.cc + src/gc-sections.cc + src/gdb-index.cc + src/icf.cc + src/input-files.cc + src/input-sections.cc + src/linker-script.cc + src/main.cc + src/mapfile.cc + src/output-chunks.cc + src/passes.cc + src/relocatable.cc + src/shrink-sections.cc + src/thunks.cc + src/tls.cc ) if(WIN32 AND NOT MINGW) - list(APPEND MOLD_ELF_TEMPLATE_FILES elf/lto-win32.cc) + list(APPEND MOLD_ELF_TEMPLATE_FILES src/lto-win32.cc) else() - list(APPEND MOLD_ELF_TEMPLATE_FILES elf/lto-unix.cc) + list(APPEND MOLD_ELF_TEMPLATE_FILES src/lto-unix.cc) endif() if(WIN32) - list(APPEND MOLD_ELF_TEMPLATE_FILES elf/subprocess-win32.cc) + list(APPEND MOLD_ELF_TEMPLATE_FILES src/subprocess-win32.cc) else() - list(APPEND MOLD_ELF_TEMPLATE_FILES elf/subprocess-unix.cc) + list(APPEND MOLD_ELF_TEMPLATE_FILES src/subprocess-unix.cc) endif() function(mold_instantiate_templates SOURCE TARGET) @@ -358,46 +358,46 @@ endforeach() # Add other non-template source files. target_sources(mold PRIVATE - common/compress.cc - common/crc32.cc - common/demangle.cc - common/filepath.cc - common/glob.cc - common/hyperloglog.cc - common/malloc.cc - common/multi-glob.cc - common/perf.cc - common/random.cc - common/tar.cc - elf/arch-alpha.cc - elf/arch-arm32.cc - elf/arch-arm64.cc - elf/arch-i386.cc - elf/arch-m68k.cc - elf/arch-ppc32.cc - elf/arch-ppc64v1.cc - elf/arch-ppc64v2.cc - elf/arch-s390x.cc - elf/arch-sh4.cc - elf/arch-sparc64.cc - elf/arch-x86-64.cc - elf/config.cc - elf/elf.cc git-hash.cc + lib/compress.cc + lib/crc32.cc + lib/demangle.cc + lib/elf.cc + lib/filepath.cc + lib/glob.cc + lib/hyperloglog.cc + lib/malloc.cc + lib/multi-glob.cc + lib/perf.cc + lib/random.cc + lib/tar.cc + src/arch-alpha.cc + src/arch-arm32.cc + src/arch-arm64.cc + src/arch-i386.cc + src/arch-m68k.cc + src/arch-ppc32.cc + src/arch-ppc64v1.cc + src/arch-ppc64v2.cc + src/arch-s390x.cc + src/arch-sh4.cc + src/arch-sparc64.cc + src/arch-x86-64.cc + src/config.cc third-party/rust-demangle/rust-demangle.c ) if(WIN32) target_sources(mold PRIVATE - common/jobs-win32.cc - common/mapped-file-win32.cc - common/signal-win32.cc + lib/jobs-win32.cc + lib/mapped-file-win32.cc + lib/signal-win32.cc ) else() target_sources(mold PRIVATE - common/jobs-unix.cc - common/mapped-file-unix.cc - common/signal-unix.cc + lib/jobs-unix.cc + lib/mapped-file-unix.cc + lib/signal-unix.cc ) endif() diff --git a/common/archive-file.h b/lib/archive-file.h similarity index 100% rename from common/archive-file.h rename to lib/archive-file.h diff --git a/common/common.h b/lib/common.h similarity index 100% rename from common/common.h rename to lib/common.h diff --git a/common/compress.cc b/lib/compress.cc similarity index 100% rename from common/compress.cc rename to lib/compress.cc diff --git a/common/config.h.in b/lib/config.h.in similarity index 100% rename from common/config.h.in rename to lib/config.h.in diff --git a/common/crc32.cc b/lib/crc32.cc similarity index 100% rename from common/crc32.cc rename to lib/crc32.cc diff --git a/common/demangle.cc b/lib/demangle.cc similarity index 100% rename from common/demangle.cc rename to lib/demangle.cc diff --git a/elf/elf.cc b/lib/elf.cc similarity index 99% rename from elf/elf.cc rename to lib/elf.cc index 4014f8fdb4..8e3af39d0c 100644 --- a/elf/elf.cc +++ b/lib/elf.cc @@ -1,6 +1,6 @@ -#include "mold.h" +#include "elf.h" -namespace mold::elf { +namespace mold { static std::string unknown_type(u32 r_type) { char buf[50]; @@ -1059,4 +1059,4 @@ std::string rel_to_string(u32 r_type) { return rel_to_string(r_type); } -} // namespace mold::elf +} // namespace mold diff --git a/elf/elf.h b/lib/elf.h similarity index 99% rename from elf/elf.h rename to lib/elf.h index c7eafbb76c..04234e5fa6 100644 --- a/elf/elf.h +++ b/lib/elf.h @@ -1,13 +1,13 @@ #pragma once -#include "../common/integers.h" +#include "integers.h" #include #include #include #include -namespace mold::elf { +namespace mold { struct X86_64; struct I386; @@ -2313,4 +2313,4 @@ struct LOONGARCH32 { static constexpr u32 R_FUNCALL[] = { R_LARCH_B26, R_LARCH_CALL36 }; }; -} // namespace mold::elf +} // namespace mold diff --git a/common/filepath.cc b/lib/filepath.cc similarity index 100% rename from common/filepath.cc rename to lib/filepath.cc diff --git a/common/filetype.h b/lib/filetype.h similarity index 98% rename from common/filetype.h rename to lib/filetype.h index b2c46578ae..eee151b508 100644 --- a/common/filetype.h +++ b/lib/filetype.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -#include "../elf/elf.h" +#include "elf.h" namespace mold { @@ -36,8 +36,6 @@ bool is_text_file(MappedFile *mf) { template inline bool is_gcc_lto_obj(Context &ctx, MappedFile *mf) { - using namespace mold::elf; - const char *data = mf->get_contents().data(); ElfEhdr &ehdr = *(ElfEhdr *)data; ElfShdr *sh_begin = (ElfShdr *)(data + ehdr.e_shoff); @@ -91,8 +89,6 @@ inline bool is_gcc_lto_obj(Context &ctx, MappedFile *mf) { template FileType get_file_type(Context &ctx, MappedFile *mf) { - using namespace elf; - std::string_view data = mf->get_contents(); if (data.empty()) diff --git a/common/gentoo-test.sh b/lib/gentoo-test.sh similarity index 100% rename from common/gentoo-test.sh rename to lib/gentoo-test.sh diff --git a/common/glob.cc b/lib/glob.cc similarity index 100% rename from common/glob.cc rename to lib/glob.cc diff --git a/common/hyperloglog.cc b/lib/hyperloglog.cc similarity index 100% rename from common/hyperloglog.cc rename to lib/hyperloglog.cc diff --git a/common/integers.h b/lib/integers.h similarity index 100% rename from common/integers.h rename to lib/integers.h diff --git a/common/jobs-unix.cc b/lib/jobs-unix.cc similarity index 100% rename from common/jobs-unix.cc rename to lib/jobs-unix.cc diff --git a/common/jobs-win32.cc b/lib/jobs-win32.cc similarity index 100% rename from common/jobs-win32.cc rename to lib/jobs-win32.cc diff --git a/common/malloc.cc b/lib/malloc.cc similarity index 100% rename from common/malloc.cc rename to lib/malloc.cc diff --git a/common/mapped-file-unix.cc b/lib/mapped-file-unix.cc similarity index 100% rename from common/mapped-file-unix.cc rename to lib/mapped-file-unix.cc diff --git a/common/mapped-file-win32.cc b/lib/mapped-file-win32.cc similarity index 100% rename from common/mapped-file-win32.cc rename to lib/mapped-file-win32.cc diff --git a/common/multi-glob.cc b/lib/multi-glob.cc similarity index 100% rename from common/multi-glob.cc rename to lib/multi-glob.cc diff --git a/common/output-file-unix.h b/lib/output-file-unix.h similarity index 100% rename from common/output-file-unix.h rename to lib/output-file-unix.h diff --git a/common/output-file-win32.h b/lib/output-file-win32.h similarity index 100% rename from common/output-file-win32.h rename to lib/output-file-win32.h diff --git a/common/output-file.h b/lib/output-file.h similarity index 100% rename from common/output-file.h rename to lib/output-file.h diff --git a/common/perf.cc b/lib/perf.cc similarity index 100% rename from common/perf.cc rename to lib/perf.cc diff --git a/common/random.cc b/lib/random.cc similarity index 100% rename from common/random.cc rename to lib/random.cc diff --git a/common/signal-unix.cc b/lib/signal-unix.cc similarity index 100% rename from common/signal-unix.cc rename to lib/signal-unix.cc diff --git a/common/signal-win32.cc b/lib/signal-win32.cc similarity index 100% rename from common/signal-win32.cc rename to lib/signal-win32.cc diff --git a/common/siphash.h b/lib/siphash.h similarity index 100% rename from common/siphash.h rename to lib/siphash.h diff --git a/common/tar.cc b/lib/tar.cc similarity index 100% rename from common/tar.cc rename to lib/tar.cc diff --git a/common/update-git-hash.cmake b/lib/update-git-hash.cmake similarity index 100% rename from common/update-git-hash.cmake rename to lib/update-git-hash.cmake diff --git a/elf/arch-alpha.cc b/src/arch-alpha.cc similarity index 99% rename from elf/arch-alpha.cc rename to src/arch-alpha.cc index d71894342e..34a87e4be3 100644 --- a/elf/arch-alpha.cc +++ b/src/arch-alpha.cc @@ -36,7 +36,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = ALPHA; @@ -327,4 +327,4 @@ void AlphaGotSection::copy_buf(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-arm32.cc b/src/arch-arm32.cc similarity index 99% rename from elf/arch-arm32.cc rename to src/arch-arm32.cc index f35097b3f0..0ca1722137 100644 --- a/elf/arch-arm32.cc +++ b/src/arch-arm32.cc @@ -37,7 +37,7 @@ #include #include -namespace mold::elf { +namespace mold { using E = ARM32; @@ -787,4 +787,4 @@ void fixup_arm_exidx_section(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-arm64.cc b/src/arch-arm64.cc similarity index 99% rename from elf/arch-arm64.cc rename to src/arch-arm64.cc index 87e82a9d68..f848fc8c46 100644 --- a/elf/arch-arm64.cc +++ b/src/arch-arm64.cc @@ -19,7 +19,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = ARM64; @@ -628,4 +628,4 @@ void Thunk::copy_buf(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-i386.cc b/src/arch-i386.cc similarity index 99% rename from elf/arch-i386.cc rename to src/arch-i386.cc index 5b7d49c700..671b9f8261 100644 --- a/elf/arch-i386.cc +++ b/src/arch-i386.cc @@ -35,7 +35,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = I386; @@ -613,4 +613,4 @@ void InputSection::scan_relocations(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-loongarch.cc b/src/arch-loongarch.cc similarity index 99% rename from elf/arch-loongarch.cc rename to src/arch-loongarch.cc index 64b5af17b3..fad9f3ceb5 100644 --- a/elf/arch-loongarch.cc +++ b/src/arch-loongarch.cc @@ -25,7 +25,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = MOLD_TARGET; @@ -977,6 +977,6 @@ void shrink_section(Context &ctx, InputSection &isec, bool use_rvc) { isec.sh_size -= delta; } -} // namespace mold::elf +} // namespace mold #endif diff --git a/elf/arch-m68k.cc b/src/arch-m68k.cc similarity index 99% rename from elf/arch-m68k.cc rename to src/arch-m68k.cc index f9de3be07f..1c3a0e74a6 100644 --- a/elf/arch-m68k.cc +++ b/src/arch-m68k.cc @@ -16,7 +16,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = M68K; @@ -322,4 +322,4 @@ void InputSection::scan_relocations(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-ppc32.cc b/src/arch-ppc32.cc similarity index 99% rename from elf/arch-ppc32.cc rename to src/arch-ppc32.cc index 95ca0f25dc..22439c2fea 100644 --- a/elf/arch-ppc32.cc +++ b/src/arch-ppc32.cc @@ -42,7 +42,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = PPC32; @@ -450,4 +450,4 @@ void Thunk::copy_buf(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-ppc64v1.cc b/src/arch-ppc64v1.cc similarity index 99% rename from elf/arch-ppc64v1.cc rename to src/arch-ppc64v1.cc index 48db46acb0..6895867fd4 100644 --- a/elf/arch-ppc64v1.cc +++ b/src/arch-ppc64v1.cc @@ -50,7 +50,7 @@ #include #include -namespace mold::elf { +namespace mold { using E = PPC64V1; @@ -689,4 +689,4 @@ void PPC64OpdSection::copy_buf(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-ppc64v2.cc b/src/arch-ppc64v2.cc similarity index 99% rename from elf/arch-ppc64v2.cc rename to src/arch-ppc64v2.cc index 2f3cc832aa..ff2100aa48 100644 --- a/elf/arch-ppc64v2.cc +++ b/src/arch-ppc64v2.cc @@ -82,7 +82,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = PPC64V2; @@ -677,4 +677,4 @@ u64 get_eflags(Context &ctx) { return 2; } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-riscv.cc b/src/arch-riscv.cc similarity index 99% rename from elf/arch-riscv.cc rename to src/arch-riscv.cc index 0509ffdbbd..f28229c2d6 100644 --- a/elf/arch-riscv.cc +++ b/src/arch-riscv.cc @@ -19,14 +19,13 @@ #if MOLD_RV64LE || MOLD_RV64BE || MOLD_RV32LE || MOLD_RV32BE -#include "elf.h" #include "mold.h" #include #include #include -namespace mold::elf { +namespace mold { using E = MOLD_TARGET; @@ -1233,6 +1232,6 @@ void RiscvAttributesSection::copy_buf(Context &ctx) { write_vector(ctx.buf + this->shdr.sh_offset, contents); } -} // namespace mold::elf +} // namespace mold #endif diff --git a/elf/arch-s390x.cc b/src/arch-s390x.cc similarity index 99% rename from elf/arch-s390x.cc rename to src/arch-s390x.cc index f66e4b370b..bcfb659d9e 100644 --- a/elf/arch-s390x.cc +++ b/src/arch-s390x.cc @@ -37,7 +37,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = S390X; @@ -486,4 +486,4 @@ void InputSection::scan_relocations(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-sh4.cc b/src/arch-sh4.cc similarity index 99% rename from elf/arch-sh4.cc rename to src/arch-sh4.cc index bf3070488f..7a52823bcf 100644 --- a/elf/arch-sh4.cc +++ b/src/arch-sh4.cc @@ -60,7 +60,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = SH4; @@ -373,4 +373,4 @@ void InputSection::scan_relocations(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-sparc64.cc b/src/arch-sparc64.cc similarity index 99% rename from elf/arch-sparc64.cc rename to src/arch-sparc64.cc index 3d63309010..d5d2b92c3d 100644 --- a/elf/arch-sparc64.cc +++ b/src/arch-sparc64.cc @@ -58,7 +58,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { using E = SPARC64; @@ -651,4 +651,4 @@ void InputSection::scan_relocations(Context &ctx) { } } -} // namespace mold::elf +} // namespace mold diff --git a/elf/arch-x86-64.cc b/src/arch-x86-64.cc similarity index 99% rename from elf/arch-x86-64.cc rename to src/arch-x86-64.cc index 1bf4f8c1a4..80a114d4bd 100644 --- a/elf/arch-x86-64.cc +++ b/src/arch-x86-64.cc @@ -30,7 +30,7 @@ #include -namespace mold::elf { +namespace mold { using E = X86_64; @@ -908,4 +908,4 @@ void rewrite_endbr(Context &ctx) { keep(sym); } -} // namespace mold::elf +} // namespace mold diff --git a/elf/cmdline.cc b/src/cmdline.cc similarity index 99% rename from elf/cmdline.cc rename to src/cmdline.cc index 12a745500c..af2595af17 100644 --- a/elf/cmdline.cc +++ b/src/cmdline.cc @@ -15,7 +15,7 @@ # define STDERR_FILENO (_fileno(stderr)) #endif -namespace mold::elf { +namespace mold { inline const char helpmsg[] = R"( Options: @@ -1524,4 +1524,4 @@ using E = MOLD_TARGET; template std::vector expand_response_files(Context &, char **); template std::vector parse_nonpositional_args(Context &ctx); -} // namespace mold::elf +} // namespace mold diff --git a/elf/config.cc b/src/config.cc similarity index 85% rename from elf/config.cc rename to src/config.cc index 55db960345..af578ab821 100644 --- a/elf/config.cc +++ b/src/config.cc @@ -1,7 +1,7 @@ #include "mold.h" #include "config.h" -namespace mold::elf { +namespace mold { std::string get_mold_version() { if (mold_git_hash.empty()) @@ -10,4 +10,4 @@ std::string get_mold_version() { "; compatible with GNU ld)"; } -} // namespace mold::elf +} // namespace mold diff --git a/elf/gc-sections.cc b/src/gc-sections.cc similarity index 99% rename from elf/gc-sections.cc rename to src/gc-sections.cc index 34334a7cea..efc6cd6dc7 100644 --- a/elf/gc-sections.cc +++ b/src/gc-sections.cc @@ -7,7 +7,7 @@ #include #include -namespace mold::elf { +namespace mold { template static bool should_keep(const InputSection &isec) { @@ -172,4 +172,4 @@ using E = MOLD_TARGET; template void gc_sections(Context &ctx); -} // namespace mold::elf +} // namespace mold diff --git a/elf/gdb-index.cc b/src/gdb-index.cc similarity index 99% rename from elf/gdb-index.cc rename to src/gdb-index.cc index d13ec49df5..a87b769180 100644 --- a/elf/gdb-index.cc +++ b/src/gdb-index.cc @@ -60,7 +60,7 @@ #include #include -namespace mold::elf { +namespace mold { enum DwarfKind { DWARF2_32, DWARF5_32, DWARF2_64, DWARF5_64 }; @@ -791,4 +791,4 @@ using E = MOLD_TARGET; template void write_gdb_index(Context &); -} // namespace mold::elf +} // namespace mold diff --git a/elf/icf.cc b/src/icf.cc similarity index 99% rename from elf/icf.cc rename to src/icf.cc index 1d8cb8fac5..cdf70760ee 100644 --- a/elf/icf.cc +++ b/src/icf.cc @@ -65,7 +65,7 @@ // conditions. #include "mold.h" -#include "../common/siphash.h" +#include "../lib/siphash.h" #include #include @@ -91,7 +91,7 @@ template <> struct hash { }; } -namespace mold::elf { +namespace mold { static u8 hmac_key[16]; @@ -612,4 +612,4 @@ using E = MOLD_TARGET; template void icf_sections(Context &ctx); -} // namespace mold::elf +} // namespace mold diff --git a/elf/input-files.cc b/src/input-files.cc similarity index 99% rename from elf/input-files.cc rename to src/input-files.cc index ba20f46fb3..c61ed5a85e 100644 --- a/elf/input-files.cc +++ b/src/input-files.cc @@ -8,7 +8,7 @@ # include #endif -namespace mold::elf { +namespace mold { // If we haven't seen the same `key` before, create a new instance // of Symbol and returns it. Otherwise, returns the previously- @@ -1497,4 +1497,4 @@ template std::string_view demangle(const Symbol &); template std::ostream &operator<<(std::ostream &, const Symbol &); template std::ostream &operator<<(std::ostream &, const InputFile &); -} // namespace mold::elf +} // namespace mold diff --git a/elf/input-sections.cc b/src/input-sections.cc similarity index 99% rename from elf/input-sections.cc rename to src/input-sections.cc index a7295221e4..b0e18a8c62 100644 --- a/elf/input-sections.cc +++ b/src/input-sections.cc @@ -4,7 +4,7 @@ #include #include -namespace mold::elf { +namespace mold { typedef enum { NONE, ERROR, COPYREL, DYN_COPYREL, PLT, CPLT, DYN_CPLT, DYNREL, @@ -675,4 +675,4 @@ template bool cie_equals(const CieRecord &, const CieRecord &); template class InputSection; template class MergeableSection; -} // namespace mold::elf +} // namespace mold diff --git a/elf/linker-script.cc b/src/linker-script.cc similarity index 99% rename from elf/linker-script.cc rename to src/linker-script.cc index c114aeff5b..6fe5dab651 100644 --- a/elf/linker-script.cc +++ b/src/linker-script.cc @@ -8,7 +8,7 @@ #include #include -namespace mold::elf { +namespace mold { static std::string_view get_line(std::string_view input, const char *pos) { assert(input.data() <= pos); @@ -421,4 +421,4 @@ template class Script; template std::vector parse_dynamic_list(Context &, std::string_view); -} // namespace mold::elf +} // namespace mold diff --git a/elf/lto-unix.cc b/src/lto-unix.cc similarity index 99% rename from elf/lto-unix.cc rename to src/lto-unix.cc index 09d5590065..e8c758787c 100644 --- a/elf/lto-unix.cc +++ b/src/lto-unix.cc @@ -95,7 +95,7 @@ # define LOG std::ostringstream() #endif -namespace mold::elf { +namespace mold { // Global variables // We store LTO-related information to global variables, @@ -746,4 +746,4 @@ template ObjectFile *read_lto_object(Context &, MappedFile *); template std::vector *> do_lto(Context &); template void lto_cleanup(Context &); -} // namespace mold::elf +} // namespace mold diff --git a/elf/lto-win32.cc b/src/lto-win32.cc similarity index 91% rename from elf/lto-win32.cc rename to src/lto-win32.cc index 456e406fac..0cc9bda13a 100644 --- a/elf/lto-win32.cc +++ b/src/lto-win32.cc @@ -1,7 +1,7 @@ #include "mold.h" #include "lto.h" -namespace mold::elf { +namespace mold { template ObjectFile *read_lto_object(Context &ctx, MappedFile *mf) { @@ -22,4 +22,4 @@ template ObjectFile *read_lto_object(Context &, MappedFile *); template std::vector *> do_lto(Context &); template void lto_cleanup(Context &); -} // namespace mold::elf +} // namespace mold diff --git a/elf/lto.h b/src/lto.h similarity index 98% rename from elf/lto.h rename to src/lto.h index 5f2225d268..f17955340c 100644 --- a/elf/lto.h +++ b/src/lto.h @@ -1,6 +1,6 @@ #pragma once -#include "../common/integers.h" +#include "../lib/integers.h" namespace mold { diff --git a/elf/main.cc b/src/main.cc similarity index 98% rename from elf/main.cc rename to src/main.cc index 800be687b1..799016ca2f 100644 --- a/elf/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ #include "mold.h" -#include "../common/archive-file.h" -#include "../common/output-file.h" +#include "../lib/archive-file.h" +#include "../lib/output-file.h" #include #include @@ -23,11 +23,11 @@ #ifdef MOLD_X86_64 int main(int argc, char **argv) { - return mold::elf::elf_main(argc, argv); + return mold::mold_main(argc, argv); } #endif -namespace mold::elf { +namespace mold { // Read the beginning of a given file and returns its machine type // (e.g. EM_X86_64 or EM_386). @@ -340,7 +340,7 @@ static void read_input_files(Context &ctx, std::span args) { } template -int elf_main(int argc, char **argv) { +int mold_main(int argc, char **argv) { Context ctx; // Process -run option first. process_run_subcommand() does not return. @@ -716,6 +716,6 @@ int elf_main(int argc, char **argv) { using E = MOLD_TARGET; -template int elf_main(int, char **); +template int mold_main(int, char **); -} // namespace mold::elf +} // namespace mold diff --git a/elf/mapfile.cc b/src/mapfile.cc similarity index 98% rename from elf/mapfile.cc rename to src/mapfile.cc index 4e730dd99e..8d60971ba1 100644 --- a/elf/mapfile.cc +++ b/src/mapfile.cc @@ -7,7 +7,7 @@ #include #include -namespace mold::elf { +namespace mold { template using Map = @@ -114,4 +114,4 @@ using E = MOLD_TARGET; template void print_map(Context &ctx); -} // namespace mold::elf +} // namespace mold diff --git a/elf/mold-wrapper.c b/src/mold-wrapper.c similarity index 100% rename from elf/mold-wrapper.c rename to src/mold-wrapper.c diff --git a/elf/mold.h b/src/mold.h similarity index 99% rename from elf/mold.h rename to src/mold.h index 3b72fd4190..fbef659ba9 100644 --- a/elf/mold.h +++ b/src/mold.h @@ -1,7 +1,7 @@ #pragma once -#include "elf.h" -#include "../common/common.h" +#include "../lib/common.h" +#include "../lib/elf.h" #include #include @@ -34,7 +34,7 @@ # include #endif -namespace mold::elf { +namespace mold { template class InputFile; template class InputSection; @@ -2038,9 +2038,7 @@ template void read_file(Context &ctx, ReaderContext &rctx, MappedFile *mf); template -int elf_main(int argc, char **argv); - -int main(int argc, char **argv); +int mold_main(int argc, char **argv); template std::ostream &operator<<(std::ostream &out, const InputFile &file); @@ -2995,4 +2993,4 @@ inline bool is_c_identifier(std::string_view s) { return true; } -} // namespace mold::elf +} // namespace mold diff --git a/elf/output-chunks.cc b/src/output-chunks.cc similarity index 99% rename from elf/output-chunks.cc rename to src/output-chunks.cc index f164dd5eef..50f1143c36 100644 --- a/elf/output-chunks.cc +++ b/src/output-chunks.cc @@ -9,7 +9,7 @@ #include #include -namespace mold::elf { +namespace mold { // The hash function for .hash. static u32 elf_hash(std::string_view name) { @@ -2954,4 +2954,4 @@ template OutputSection *find_section(Context &, std::string_view); template i64 to_phdr_flags(Context &ctx, Chunk *chunk); template ElfSym to_output_esym(Context &, Symbol &, u32, U32 *); -} // namespace mold::elf +} // namespace mold diff --git a/elf/passes.cc b/src/passes.cc similarity index 99% rename from elf/passes.cc rename to src/passes.cc index d948b0ed3e..87fc278dd9 100644 --- a/elf/passes.cc +++ b/src/passes.cc @@ -1,6 +1,6 @@ #include "mold.h" #include "blake3.h" -#include "../common/output-file.h" +#include "../lib/output-file.h" #include #include @@ -13,49 +13,49 @@ #include #include -namespace mold::elf { +namespace mold { -// Since elf_main is a template, we can't run it without a type parameter. -// We speculatively run elf_main with X86_64, and if the speculation was +// Since mold_main is a template, we can't run it without a type parameter. +// We speculatively run mold_main with X86_64, and if the speculation was // wrong, re-run it with an actual machine type. template int redo_main(Context &ctx, int argc, char **argv) { std::string_view target = ctx.arg.emulation; if (target == I386::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == ARM64::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == ARM32::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == RV64LE::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == RV64BE::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == RV32LE::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == RV32BE::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == PPC32::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == PPC64V1::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == PPC64V2::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == S390X::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == SPARC64::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == M68K::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == SH4::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == ALPHA::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == LOONGARCH32::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); if (target == LOONGARCH64::target_name) - return elf_main(argc, argv); + return mold_main(argc, argv); unreachable(); } @@ -3283,4 +3283,4 @@ template void write_separate_debug_file(Context &); template void write_dependency_file(Context &); template void show_stats(Context &); -} // namespace mold::elf +} // namespace mold diff --git a/elf/relocatable.cc b/src/relocatable.cc similarity index 99% rename from elf/relocatable.cc rename to src/relocatable.cc index 55ce0f5b38..d582c2edc7 100644 --- a/elf/relocatable.cc +++ b/src/relocatable.cc @@ -35,7 +35,7 @@ #include #include -namespace mold::elf { +namespace mold { // Create linker-synthesized sections template @@ -194,4 +194,4 @@ using E = MOLD_TARGET; template void combine_objects(Context &); -} // namespace mold::elf +} // namespace mold diff --git a/elf/shrink-sections.cc b/src/shrink-sections.cc similarity index 99% rename from elf/shrink-sections.cc rename to src/shrink-sections.cc index 726e4a2667..baab836914 100644 --- a/elf/shrink-sections.cc +++ b/src/shrink-sections.cc @@ -62,7 +62,7 @@ #include -namespace mold::elf { +namespace mold { using E = MOLD_TARGET; @@ -142,6 +142,6 @@ i64 compute_distance(Context &ctx, Symbol &sym, return S + A - P; } -} // namespace mold::elf +} // namespace mold #endif diff --git a/elf/subprocess-unix.cc b/src/subprocess-unix.cc similarity index 98% rename from elf/subprocess-unix.cc rename to src/subprocess-unix.cc index 12bdf39c72..44e5e65a32 100644 --- a/elf/subprocess-unix.cc +++ b/src/subprocess-unix.cc @@ -9,7 +9,7 @@ #include #include -namespace mold::elf { +namespace mold { #ifdef MOLD_X86_64 static int pipe_write_fd = -1; @@ -126,4 +126,4 @@ using E = MOLD_TARGET; template void process_run_subcommand(Context &, int, char **); -} // namespace mold::elf +} // namespace mold diff --git a/elf/subprocess-win32.cc b/src/subprocess-win32.cc similarity index 87% rename from elf/subprocess-win32.cc rename to src/subprocess-win32.cc index 8fa48c194b..fb33682735 100644 --- a/elf/subprocess-win32.cc +++ b/src/subprocess-win32.cc @@ -1,6 +1,6 @@ #include "mold.h" -namespace mold::elf { +namespace mold { #ifdef MOLD_X86_64 void fork_child() {} @@ -17,4 +17,4 @@ using E = MOLD_TARGET; template void process_run_subcommand(Context &, int, char **); -} // namespace mold::elf +} // namespace mold diff --git a/elf/thunks.cc b/src/thunks.cc similarity index 99% rename from elf/thunks.cc rename to src/thunks.cc index a195a5ed2e..cafbe8b141 100644 --- a/elf/thunks.cc +++ b/src/thunks.cc @@ -27,7 +27,7 @@ #include #include -namespace mold::elf { +namespace mold { using E = MOLD_TARGET; @@ -294,6 +294,6 @@ void OutputSection::create_range_extension_thunks(Context &ctx) { std::max(this->shdr.sh_addralign, 1 << isec->p2align); } -} // namespace mold::elf +} // namespace mold #endif diff --git a/elf/tls.cc b/src/tls.cc similarity index 99% rename from elf/tls.cc rename to src/tls.cc index fc4f955fad..c264adf114 100644 --- a/elf/tls.cc +++ b/src/tls.cc @@ -122,7 +122,7 @@ #include "mold.h" -namespace mold::elf { +namespace mold { // Returns the TP address which can be used for efficient TLV accesses in // the main executable. TP at runtime refers to a per-process TLS block @@ -189,4 +189,4 @@ using E = MOLD_TARGET; template u64 get_tp_addr(const ElfPhdr &); template u64 get_dtp_addr(const ElfPhdr &); -} // namespace mold::elf +} // namespace mold