forked from rui314/mold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapfile.cc
47 lines (39 loc) · 1.51 KB
/
mapfile.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "mold.h"
#include <iomanip>
#include <ios>
#include <unordered_map>
void print_map() {
// Construct a section-to-symbol map.
std::unordered_map<InputChunk *, std::vector<Symbol *>> map;
for (ObjectFile *file : out::objs)
for (Symbol *sym : file->symbols)
if (sym->file == file && sym->input_section)
map[sym->input_section].push_back(sym);
for (auto &pair : map) {
std::vector<Symbol *> &vec = pair.second;
sort(vec, [](Symbol *a, Symbol *b) { return a->value < b->value; });
}
std::cout << " VMA Size Align Out In Symbol\n";
for (OutputChunk *osec : out::chunks) {
std::cout << std::setw(16) << (u64)osec->shdr.sh_addr
<< std::setw(9) << (u64)osec->shdr.sh_size
<< std::setw(6) << (u64)osec->shdr.sh_addralign
<< " " << osec->name << "\n";
if (osec->kind != OutputChunk::REGULAR)
continue;
for (InputChunk *mem : ((OutputSection *)osec)->members) {
std::cout << std::setw(16) << (osec->shdr.sh_addr + mem->offset)
<< std::setw(9) << (u64)mem->shdr.sh_size
<< std::setw(6) << (u64)mem->shdr.sh_addralign
<< " " << *mem << "\n";
auto it = map.find(mem);
if (it == map.end())
continue;
std::vector<Symbol *> syms = it->second;
for (Symbol *sym : syms)
std::cout << std::setw(16) << sym->get_addr()
<< " 0 0 "
<< sym->name << "\n";
}
}
}