Changed resource alignment behaviour for ELF64 binaries.
The current behaviour of aligning to the maximum value of p_align seen is problematic for x86_64, as the default segment alignment is 2MB. This causes all x86_64 binaries to be padded to at least 2MB when resources are added to them. There is no need to align to p_align in the file itself (it's only an in-memory requirement), therefore instead just align up to an 8-byte boundary. The current behaviour is retained for ELF32, so this won't cause any compatibility problems (there are no existing ELF64 BeOS/Haiku binaries to worry about).
This commit is contained in:
@@ -636,12 +636,24 @@ ResourceFile::_InitELFXFile(BFile& file, uint64 fileSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// align the offset
|
// align the offset
|
||||||
if (resourceAlignment < kELFMinResourceAlignment)
|
if (fileHeader.e_ident[EI_CLASS] == ELFCLASS64) {
|
||||||
resourceAlignment = kELFMinResourceAlignment;
|
// For ELF64 binaries we use a different alignment behaviour. It is
|
||||||
if (resourceAlignment > kELFMaxResourceAlignment) {
|
// not necessary to align the position of the resources in the file to
|
||||||
throw Exception(B_IO_ERROR, "The ELF object file requires an invalid "
|
// the maximum value of p_align, and in fact on x86_64 this behaviour
|
||||||
"alignment: %lu.", resourceAlignment);
|
// causes an undesirable effect: since the default segment alignment is
|
||||||
|
// 2MB, aligning to p_align causes all binaries to be at least 2MB when
|
||||||
|
// resources have been added. So, just align to an 8-byte boundary.
|
||||||
|
resourceAlignment = 8;
|
||||||
|
} else {
|
||||||
|
// Retain previous alignment behaviour for compatibility.
|
||||||
|
if (resourceAlignment < kELFMinResourceAlignment)
|
||||||
|
resourceAlignment = kELFMinResourceAlignment;
|
||||||
|
if (resourceAlignment > kELFMaxResourceAlignment) {
|
||||||
|
throw Exception(B_IO_ERROR, "The ELF object file requires an "
|
||||||
|
"invalid alignment: %lu.", resourceAlignment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceOffset = align_value(resourceOffset, resourceAlignment);
|
resourceOffset = align_value(resourceOffset, resourceAlignment);
|
||||||
if (resourceOffset >= fileSize) {
|
if (resourceOffset >= fileSize) {
|
||||||
// throw Exception("The ELF object file does not contain resources.");
|
// throw Exception("The ELF object file does not contain resources.");
|
||||||
|
|||||||
Reference in New Issue
Block a user