Skip to content

Commit e44cba9

Browse files
authored
fixes the address size computation in the llvm backend (#1330)
The `getBytesInAddress` virutal member-function for ELF files is implemented incorrectly in LLVM, ``` template <class ELFT> uint8_t ELFObjectFile<ELFT>::getBytesInAddress() const { return ELFT::Is64Bits ? 8 : 4; } ``` It is actually a static file that returns 32 for ELF32 and 64 for ELF64, which has nothing to do with the actual bitness of the target architecture address. The if is using the information obtained from the target (triple) and falls back to `getBytesInAddress` only if the target is not 16, 32, or 64 bit (the target interface is also strange as it doesn't allow any other values).
1 parent 1f632b2 commit e44cba9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/bap_llvm/llvm_loader.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ void verbose_fails(const error_or<T> &loaded) {
9898
}
9999
}
100100

101+
int addr_size(const Triple &target, const object::ObjectFile *obj) {
102+
if (target.isArch64Bit()) {
103+
return 64;
104+
} else if (target.isArch32Bit()) {
105+
return 32;
106+
} else if (target.isArch16Bit()) {
107+
return 16;
108+
} else {
109+
return obj->getBytesInAddress() * 8;
110+
}
111+
}
112+
101113
void emit_common_header(ogre_doc &s, const object::ObjectFile *obj) {
102114
s.raw_entry(scheme);
103115
auto target = obj->makeTriple();
@@ -106,7 +118,7 @@ void emit_common_header(ogre_doc &s, const object::ObjectFile *obj) {
106118
s.entry("vendor") << target.getVendorName();
107119
s.entry("system") << target.getOSName();
108120
s.entry("abi") << prim::string_of_abi(target.getEnvironment());
109-
s.entry("bits") << (obj->getBytesInAddress() * 8);
121+
s.entry("bits") << addr_size(target, obj);
110122
s.entry("is-little-endian") << target.isLittleEndian();
111123
}
112124

0 commit comments

Comments
 (0)