From 55f0289a4121fc76ff6df393931c227703663f30 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 29 Sep 2024 20:42:52 +0900 Subject: [PATCH] Non-SHF_ALLOC sections' addresses should be displayed as zero for --Map --- src/mapfile.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/mapfile.cc b/src/mapfile.cc index 6aeb493c62..877361865d 100644 --- a/src/mapfile.cc +++ b/src/mapfile.cc @@ -51,7 +51,7 @@ void print_map(Context &ctx) { std::ofstream file; if (!ctx.arg.Map.empty()) { - file.open(ctx.arg.Map.c_str()); + file.open(ctx.arg.Map); if (!file.is_open()) Fatal(ctx) << "cannot open " << ctx.arg.Map << ": " << errno_string(); out = &file; @@ -63,28 +63,32 @@ void print_map(Context &ctx) { // Print a mapfile. *out << " VMA Size Align Out In Symbol\n"; - for (Chunk *osec : ctx.chunks) { + for (Chunk *chunk : ctx.chunks) { *out << std::showbase - << std::setw(18) << std::hex << (u64)osec->shdr.sh_addr << std::dec - << std::setw(11) << (u64)osec->shdr.sh_size - << std::setw(6) << (u64)osec->shdr.sh_addralign - << " " << osec->name << "\n"; + << std::setw(18) << std::hex << (u64)chunk->shdr.sh_addr << std::dec + << std::setw(11) << (u64)chunk->shdr.sh_size + << std::setw(6) << (u64)chunk->shdr.sh_addralign + << " " << chunk->name << "\n"; - if (!osec->to_osec()) + OutputSection *osec = chunk->to_osec(); + if (!osec) continue; - std::span *> members = ((OutputSection *)osec)->members; + std::span *> members = osec->members; std::vector bufs(members.size()); tbb::parallel_for((i64)0, (i64)members.size(), [&](i64 i) { InputSection *mem = members[i]; std::ostringstream ss; - u64 addr = osec->shdr.sh_addr + mem->offset; + + u64 addr = 0; + if (osec->shdr.sh_flags & SHF_ALLOC) + addr = osec->shdr.sh_addr + mem->offset; ss << std::showbase << std::setw(18) << std::hex << addr << std::dec << std::setw(11) << (u64)mem->sh_size - << std::setw(6) << (1 << (u64)mem->p2align) + << std::setw(6) << (1 << mem->p2align) << " " << *mem << "\n"; typename Map::const_accessor acc;