Skip to content

Commit

Permalink
Non-SHF_ALLOC sections' addresses should be displayed as zero for --Map
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 30, 2024
1 parent 36dd6ba commit 55f0289
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/mapfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void print_map(Context<E> &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;
Expand All @@ -63,28 +63,32 @@ void print_map(Context<E> &ctx) {
// Print a mapfile.
*out << " VMA Size Align Out In Symbol\n";

for (Chunk<E> *osec : ctx.chunks) {
for (Chunk<E> *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<E> *osec = chunk->to_osec();
if (!osec)
continue;

std::span<InputSection<E> *> members = ((OutputSection<E> *)osec)->members;
std::span<InputSection<E> *> members = osec->members;
std::vector<std::string> bufs(members.size());

tbb::parallel_for((i64)0, (i64)members.size(), [&](i64 i) {
InputSection<E> *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<E>::const_accessor acc;
Expand Down

0 comments on commit 55f0289

Please sign in to comment.