Skip to content

Commit eb58832

Browse files
committed
Update elf handling in 32-bit, use the larger type to handle both 32 and 64-bit in the same code paths
1 parent 934cb37 commit eb58832

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/binary/elf.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ namespace detail {
168168
const auto& sections = sections_res.unwrap_value();
169169
for(const auto& section : sections) {
170170
if(string_view(strtab.data() + section.sh_name) == ".text") {
171-
vec.push_back(pc_range{section.sh_addr, section.sh_addr + section.sh_size});
171+
vec.push_back(
172+
pc_range{to<frame_ptr>(section.sh_addr), to<frame_ptr>(section.sh_addr + section.sh_size)}
173+
);
172174
}
173175
}
174176
return vec;
@@ -330,7 +332,10 @@ namespace detail {
330332
return internal_error("requested strtab section not a strtab (requested {} of {})", index, file->path());
331333
}
332334
entry.data.resize(section.sh_size + 1);
333-
auto read_res = file->read_bytes(span<char>{entry.data.data(), section.sh_size}, section.sh_offset);
335+
auto read_res = file->read_bytes(
336+
span<char>{entry.data.data(), to<std::size_t>(section.sh_size)},
337+
section.sh_offset
338+
);
334339
if(!read_res) {
335340
return read_res.unwrap_error();
336341
}

src/binary/elf.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
CPPTRACE_BEGIN_NAMESPACE
1717
namespace detail {
18-
using Elf_Addr = std::uintptr_t;
19-
using Elf_Off = std::uintptr_t;
20-
using Elf_Xword = std::size_t;
21-
2218
// TODO: make methods const and a bunch of members mutable
2319
class elf {
2420
std::unique_ptr<base_file> file;
@@ -40,10 +36,10 @@ namespace detail {
4036
struct section_info {
4137
uint32_t sh_name;
4238
uint32_t sh_type;
43-
Elf_Addr sh_addr;
44-
Elf_Off sh_offset;
45-
Elf_Xword sh_size;
46-
Elf_Xword sh_entsize;
39+
uint64_t sh_addr;
40+
uint64_t sh_offset;
41+
uint64_t sh_size;
42+
uint64_t sh_entsize;
4743
uint32_t sh_link;
4844
};
4945
bool tried_to_load_sections = false;

0 commit comments

Comments
 (0)