Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 29, 2024
1 parent 91b6818 commit 36dd6ba
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/mapfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ template <typename E>
using Map =
tbb::concurrent_hash_map<InputSection<E> *, std::vector<Symbol<E> *>>;

template <typename E>
static std::unique_ptr<std::ofstream> open_output_file(Context<E> &ctx) {
std::unique_ptr<std::ofstream> file(new std::ofstream);
file->open(ctx.arg.Map.c_str());
if (!file->is_open())
Fatal(ctx) << "cannot open " << ctx.arg.Map << ": " << errno_string();
return file;
}

template <typename E>
static Map<E> get_map(Context<E> &ctx) {
Map<E> map;
Expand Down Expand Up @@ -57,11 +48,13 @@ void print_map(Context<E> &ctx) {
Timer t(ctx, "print_map");

std::ostream *out = &std::cout;
std::unique_ptr<std::ofstream> file;
std::ofstream file;

if (!ctx.arg.Map.empty()) {
file = open_output_file(ctx);
out = file.get();
file.open(ctx.arg.Map.c_str());
if (!file.is_open())
Fatal(ctx) << "cannot open " << ctx.arg.Map << ": " << errno_string();
out = &file;
}

// Construct a section-to-symbol map.
Expand Down

0 comments on commit 36dd6ba

Please sign in to comment.