1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-26 01:44:29 +03:00
This commit is contained in:
Rui Ueyama 2021-04-06 13:37:01 +09:00
parent 852b6cbc39
commit 32ca7046cf
4 changed files with 14 additions and 10 deletions

View File

@ -220,7 +220,7 @@ static void show_stats(Context<E> &ctx) {
undefined += obj->symbols.size() - obj->first_global;
for (InputSection<E> *sec : obj->sections) {
if (!sec)
if (!sec || !sec->is_alive)
continue;
static Counter alloc("reloc_alloc");
@ -494,7 +494,8 @@ int do_main(int argc, char **argv) {
t_before_copy.stop();
// Create an output file
OutputFile<E> *file = OutputFile<E>::open(ctx, ctx.arg.output, filesize);
std::unique_ptr<OutputFile<E>> file =
OutputFile<E>::open(ctx, ctx.arg.output, filesize);
ctx.buf = file->buf;
Timer t_copy("copy");

5
mold.h
View File

@ -955,8 +955,11 @@ void parse_dynamic_list(Context<E> &ctx, std::string path);
template <typename E>
class OutputFile {
public:
static OutputFile *open(Context<E> &ctx, std::string path, u64 filesize);
static std::unique_ptr<OutputFile>
open(Context<E> &ctx, std::string path, u64 filesize);
virtual void close(Context<E> &ctx) = 0;
virtual ~OutputFile() {}
u8 *buf;
static inline char *tmpfile;

View File

@ -84,7 +84,7 @@ public:
};
template <typename E>
OutputFile<E> *
std::unique_ptr<OutputFile<E>>
OutputFile<E>::open(Context<E> &ctx, std::string path, u64 filesize) {
Timer t("open_file");
@ -93,11 +93,11 @@ OutputFile<E>::open(Context<E> &ctx, std::string path, u64 filesize) {
if (stat(path.c_str(), &st) == 0 && (st.st_mode & S_IFMT) != S_IFREG)
is_special = true;
OutputFile<E> *file;
std::unique_ptr<OutputFile<E>> file;
if (is_special)
file = new MallocOutputFile<E>(ctx, path, filesize);
file = std::make_unique<MallocOutputFile<E>>(ctx, path, filesize);
else
file = new MemoryMappedOutputFile<E>(ctx, path, filesize);
file = std::make_unique<MemoryMappedOutputFile<E>>(ctx, path, filesize);
if (ctx.arg.filler != -1)
memset(file->buf, ctx.arg.filler, filesize);
@ -105,9 +105,9 @@ OutputFile<E>::open(Context<E> &ctx, std::string path, u64 filesize) {
}
template
OutputFile<X86_64> *
std::unique_ptr<OutputFile<X86_64>>
OutputFile<X86_64>::open(Context<X86_64> &ctx, std::string path, u64 filesize);
template
OutputFile<I386> *
std::unique_ptr<OutputFile<I386>>
OutputFile<I386>::open(Context<I386> &ctx, std::string path, u64 filesize);

View File

@ -272,7 +272,7 @@ void bin_sections(Context<E> &ctx) {
tbb::parallel_for((i64)0, (i64)slices.size(), [&](i64 i) {
for (ObjectFile<E> *file : slices[i])
for (InputSection<E> *isec : file->sections)
if (isec)
if (isec && isec->is_alive)
groups[i][isec->output_section->idx].push_back(isec);
});