[haiku-commits] haiku: hrev44450 - src/kits/storage

  • From: alex@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 1 Aug 2012 11:42:33 +0200 (CEST)

hrev44450 adds 1 changeset to branch 'master'
old head: 57e2ce542e59a69f405a60f1ab7a3e0e54e4f6a2
new head: f7010474bbc31cf0800e1dd0b7d0b03bb1b25b9b

----------------------------------------------------------------------------

f701047: 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).

                                      [ Alex Smith <alex@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44450
Commit:      f7010474bbc31cf0800e1dd0b7d0b03bb1b25b9b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f701047
Author:      Alex Smith <alex@xxxxxxxxxxxxxxxx>
Date:        Wed Aug  1 09:35:34 2012 UTC

----------------------------------------------------------------------------

1 file changed, 17 insertions(+), 5 deletions(-)
src/kits/storage/ResourceFile.cpp |   22 +++++++++++++++++-----

----------------------------------------------------------------------------

diff --git a/src/kits/storage/ResourceFile.cpp 
b/src/kits/storage/ResourceFile.cpp
index 1f19dd6..48d5565 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.");


Other related posts:

  • » [haiku-commits] haiku: hrev44450 - src/kits/storage - alex