Skip to content

Commit

Permalink
Reorganize directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Aug 14, 2024
1 parent 7571305 commit 5b85949
Show file tree
Hide file tree
Showing 68 changed files with 163 additions and 170 deletions.
112 changes: 56 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions elf/elf.cc → lib/elf.cc
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -1059,4 +1059,4 @@ std::string rel_to_string<LOONGARCH32>(u32 r_type) {
return rel_to_string<LOONGARCH64>(r_type);
}

} // namespace mold::elf
} // namespace mold
6 changes: 3 additions & 3 deletions elf/elf.h → lib/elf.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include "../common/integers.h"
#include "integers.h"

#include <concepts>
#include <ostream>
#include <string>
#include <type_traits>

namespace mold::elf {
namespace mold {

struct X86_64;
struct I386;
Expand Down Expand Up @@ -2313,4 +2313,4 @@ struct LOONGARCH32 {
static constexpr u32 R_FUNCALL[] = { R_LARCH_B26, R_LARCH_CALL36 };
};

} // namespace mold::elf
} // namespace mold
File renamed without changes.
6 changes: 1 addition & 5 deletions common/filetype.h → lib/filetype.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "common.h"
#include "../elf/elf.h"
#include "elf.h"

namespace mold {

Expand Down Expand Up @@ -36,8 +36,6 @@ bool is_text_file(MappedFile *mf) {

template <typename E, typename Context, typename MappedFile>
inline bool is_gcc_lto_obj(Context &ctx, MappedFile *mf) {
using namespace mold::elf;

const char *data = mf->get_contents().data();
ElfEhdr<E> &ehdr = *(ElfEhdr<E> *)data;
ElfShdr<E> *sh_begin = (ElfShdr<E> *)(data + ehdr.e_shoff);
Expand Down Expand Up @@ -91,8 +89,6 @@ inline bool is_gcc_lto_obj(Context &ctx, MappedFile *mf) {

template <typename Context, typename MappedFile>
FileType get_file_type(Context &ctx, MappedFile *mf) {
using namespace elf;

std::string_view data = mf->get_contents();

if (data.empty())
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions elf/arch-alpha.cc → src/arch-alpha.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = ALPHA;

Expand Down Expand Up @@ -327,4 +327,4 @@ void AlphaGotSection::copy_buf(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-arm32.cc → src/arch-arm32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <tbb/parallel_for_each.h>
#include <tbb/parallel_sort.h>

namespace mold::elf {
namespace mold {

using E = ARM32;

Expand Down Expand Up @@ -787,4 +787,4 @@ void fixup_arm_exidx_section(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-arm64.cc → src/arch-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = ARM64;

Expand Down Expand Up @@ -628,4 +628,4 @@ void Thunk<E>::copy_buf(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-i386.cc → src/arch-i386.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = I386;

Expand Down Expand Up @@ -613,4 +613,4 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-loongarch.cc → src/arch-loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = MOLD_TARGET;

Expand Down Expand Up @@ -977,6 +977,6 @@ void shrink_section(Context<E> &ctx, InputSection<E> &isec, bool use_rvc) {
isec.sh_size -= delta;
}

} // namespace mold::elf
} // namespace mold

#endif
4 changes: 2 additions & 2 deletions elf/arch-m68k.cc → src/arch-m68k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = M68K;

Expand Down Expand Up @@ -322,4 +322,4 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-ppc32.cc → src/arch-ppc32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = PPC32;

Expand Down Expand Up @@ -450,4 +450,4 @@ void Thunk<E>::copy_buf(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-ppc64v1.cc → src/arch-ppc64v1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <algorithm>
#include <tbb/parallel_for_each.h>

namespace mold::elf {
namespace mold {

using E = PPC64V1;

Expand Down Expand Up @@ -689,4 +689,4 @@ void PPC64OpdSection::copy_buf(Context<E> &ctx) {
}
}

} // namespace mold::elf
} // namespace mold
4 changes: 2 additions & 2 deletions elf/arch-ppc64v2.cc → src/arch-ppc64v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

#include "mold.h"

namespace mold::elf {
namespace mold {

using E = PPC64V2;

Expand Down Expand Up @@ -677,4 +677,4 @@ u64 get_eflags(Context<E> &ctx) {
return 2;
}

} // namespace mold::elf
} // namespace mold
5 changes: 2 additions & 3 deletions elf/arch-riscv.cc → src/arch-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

#if MOLD_RV64LE || MOLD_RV64BE || MOLD_RV32LE || MOLD_RV32BE

#include "elf.h"
#include "mold.h"

#include <regex>
#include <tbb/parallel_for.h>
#include <tbb/parallel_for_each.h>

namespace mold::elf {
namespace mold {

using E = MOLD_TARGET;

Expand Down Expand Up @@ -1233,6 +1232,6 @@ void RiscvAttributesSection<E>::copy_buf(Context<E> &ctx) {
write_vector(ctx.buf + this->shdr.sh_offset, contents);
}

} // namespace mold::elf
} // namespace mold

#endif
Loading

0 comments on commit 5b85949

Please sign in to comment.