aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Smith <alex@alex-smith.me.uk>2012-08-01 10:35:34 +0100
committerAlex Smith <alex@alex-smith.me.uk>2012-08-01 10:35:34 +0100
commitf7010474bbc31cf0800e1dd0b7d0b03bb1b25b9b (patch)
treed2a811b1d3657a0027a659494aeecda4f22b92ac
parent57e2ce542e59a69f405a60f1ab7a3e0e54e4f6a2 (diff)
Changed resource alignment behaviour for ELF64 binaries.hrev44450
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).
-rw-r--r--src/kits/storage/ResourceFile.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/kits/storage/ResourceFile.cpp b/src/kits/storage/ResourceFile.cpp
index 1f19dd6ead..48d55651d3 100644
--- a/src/kits/storage/ResourceFile.cpp
+++ b/src/kits/storage/ResourceFile.cpp
@@ -636,12 +636,24 @@ ResourceFile::_InitELFXFile(BFile& file, uint64 fileSize)
}
// align the offset
- if (resourceAlignment < kELFMinResourceAlignment)
- resourceAlignment = kELFMinResourceAlignment;
- if (resourceAlignment > kELFMaxResourceAlignment) {
- throw Exception(B_IO_ERROR, "The ELF object file requires an invalid "
- "alignment: %lu.", resourceAlignment);
+ if (fileHeader.e_ident[EI_CLASS] == ELFCLASS64) {
+ // For ELF64 binaries we use a different alignment behaviour. It is
+ // not necessary to align the position of the resources in the file to
+ // the maximum value of p_align, and in fact on x86_64 this behaviour
+ // 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);
if (resourceOffset >= fileSize) {
// throw Exception("The ELF object file does not contain resources.");