[haiku-commits] haiku: hrev49728 - src/system/runtime_loader headers/private/system

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 26 Oct 2015 21:23:04 +0100 (CET)

hrev49728 adds 2 changesets to branch 'master'
old head: 1e6dd3feed715e3344f19c80898e54b33f11d736
new head: d5447eb9c02e0f64f70f2abd94a705b376ba590a
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=d5447eb9c02e+%5E1e6dd3feed71

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

078b88b12df1: runtime_loader: Randomly position only relocatable code

The use of an unreliable test for relocatability effectively broke
runtime_loader's support for non-position-independent executables, as it
would insist on randomly positioning these files' segments in memory
anyway causing the program to quickly crash.

With this change runtime_loader uses the object type specified in the
file's header to determine whether its segments can be safely relocated,
restoring support for non-PI executables.

Fixes #12427.

Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>

d5447eb9c02e: runtime_loader: Do not assume executable has dynamic segment

This prevents a crash when loading a statically linked executable.

Fixes #12287.

Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>

[ Simon South <ssouth@xxxxxxxxxxxxxx> ]

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

5 files changed, 25 insertions(+), 8 deletions(-)
headers/private/system/elf_common.h | 11 +++++++++++
src/system/runtime_loader/elf_load_image.cpp | 2 +-
src/system/runtime_loader/elf_symbol_lookup.h | 2 +-
src/system/runtime_loader/images.cpp | 16 +++++++++++-----
src/system/runtime_loader/images.h | 2 +-

############################################################################

Commit: 078b88b12df1f3be41ba3b3a7ef136309d33fdae
URL: http://cgit.haiku-os.org/haiku/commit/?id=078b88b12df1
Author: Simon South <ssouth@xxxxxxxxxxxxxx>
Date: Wed Oct 21 12:18:43 2015 UTC
Committer: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Commit-Date: Mon Oct 26 20:19:25 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/12427

runtime_loader: Randomly position only relocatable code

The use of an unreliable test for relocatability effectively broke
runtime_loader's support for non-position-independent executables, as it
would insist on randomly positioning these files' segments in memory
anyway causing the program to quickly crash.

With this change runtime_loader uses the object type specified in the
file's header to determine whether its segments can be safely relocated,
restoring support for non-PI executables.

Fixes #12427.

Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>

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

diff --git a/headers/private/system/elf_common.h
b/headers/private/system/elf_common.h
index 3e65305..23ab555 100644
--- a/headers/private/system/elf_common.h
+++ b/headers/private/system/elf_common.h
@@ -31,6 +31,17 @@
#define EI_VERSION 6
#define EI_PAD 7

+// e_type (Object file type)
+#define ET_NONE 0 // No file type
+#define ET_REL 1 // Relocatable file
+#define ET_EXEC 2 // Executable file
+#define ET_DYN 3 // Shared object file
+#define ET_CORE 4 // Core file
+#define ET_LOOS 0xfe00 // OS-specific range start
+#define ET_HIOS 0xfeff // OS-specific range end
+#define ET_LOPROC 0xff00 // Processor-specific range start
+#define ET_HIPROC 0xffff // Processor-specific range end
+
// e_machine (Architecture)
#define EM_NONE 0 // No machine
#define EM_M32 1 // AT&T WE 32100
diff --git a/src/system/runtime_loader/elf_load_image.cpp
b/src/system/runtime_loader/elf_load_image.cpp
index cfa4e34..8455645 100644
--- a/src/system/runtime_loader/elf_load_image.cpp
+++ b/src/system/runtime_loader/elf_load_image.cpp
@@ -527,7 +527,7 @@ load_image(char const* name, image_type type, const char*
rpath,
goto err2;
}

- status = map_image(fd, path, image);
+ status = map_image(fd, path, image, eheader.e_type == ET_EXEC);
if (status < B_OK) {
FATAL("%s: Could not map image: %s\n", image->path,
strerror(status));
status = B_ERROR;
diff --git a/src/system/runtime_loader/images.cpp
b/src/system/runtime_loader/images.cpp
index d851f9f..2b7f6df 100644
--- a/src/system/runtime_loader/images.cpp
+++ b/src/system/runtime_loader/images.cpp
@@ -169,9 +169,9 @@ topological_sort(image_t* image, uint32 slot, image_t**
initList,
*/
static void
get_image_region_load_address(image_t* image, uint32 index, long lastDelta,
- addr_t& loadAddress, uint32& addressSpecifier)
+ bool fixed, addr_t& loadAddress, uint32& addressSpecifier)
{
- if (image->dynamic_ptr != 0) {
+ if (!fixed) {
// relocatable image... we can afford to place wherever
if (index == 0) {
// but only the first segment gets a free ride
@@ -286,7 +286,7 @@ put_image(image_t* image)


status_t
-map_image(int fd, char const* path, image_t* image)
+map_image(int fd, char const* path, image_t* image, bool fixed)
{
// cut the file name from the path as base name for the created areas
const char* baseName = strrchr(path, '/');
@@ -304,10 +304,16 @@ map_image(int fd, char const* path, image_t* image)
uint32 addressSpecifier = B_RANDOMIZED_ANY_ADDRESS;

for (uint32 i = 0; i < image->num_regions; i++) {
+ // for BeOS compatibility: if we load an old BeOS executable, we
+ // have to relocate it, if possible - we recognize it because
the
+ // vmstart is set to 0 (hopefully always)
+ if (fixed && image->regions[i].vmstart == 0)
+ fixed = false;
+
uint32 regionAddressSpecifier;
get_image_region_load_address(image, i,
i > 0 ? loadAddress - image->regions[i - 1].vmstart : 0,
- loadAddress, regionAddressSpecifier);
+ fixed, loadAddress, regionAddressSpecifier);
if (i == 0) {
reservedAddress = loadAddress;
addressSpecifier = regionAddressSpecifier;
@@ -339,7 +345,7 @@ map_image(int fd, char const* path, image_t* image)
baseName, i, (image->regions[i].flags & RFLAG_RW) ?
"rw" : "ro");

get_image_region_load_address(image, i,
- i > 0 ? image->regions[i - 1].delta : 0, loadAddress,
+ i > 0 ? image->regions[i - 1].delta : 0, fixed,
loadAddress,
addressSpecifier);

// If the image position is arbitrary, we must let it point to
the start
diff --git a/src/system/runtime_loader/images.h
b/src/system/runtime_loader/images.h
index 7a309bb..a929040 100644
--- a/src/system/runtime_loader/images.h
+++ b/src/system/runtime_loader/images.h
@@ -50,7 +50,7 @@ void delete_image_struct(image_t* image);
void delete_image(image_t* image);
void put_image(image_t* image);

-status_t map_image(int fd, char const* path, image_t* image);
+status_t map_image(int fd, char const* path, image_t* image, bool fixed);
void unmap_image(image_t* image);
void remap_images();


############################################################################

Revision: hrev49728
Commit: d5447eb9c02e0f64f70f2abd94a705b376ba590a
URL: http://cgit.haiku-os.org/haiku/commit/?id=d5447eb9c02e
Author: Simon South <ssouth@xxxxxxxxxxxxxx>
Date: Sun Oct 25 10:27:26 2015 UTC
Committer: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Commit-Date: Mon Oct 26 20:23:30 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/12287

runtime_loader: Do not assume executable has dynamic segment

This prevents a crash when loading a statically linked executable.

Fixes #12287.

Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>

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

diff --git a/src/system/runtime_loader/elf_symbol_lookup.h
b/src/system/runtime_loader/elf_symbol_lookup.h
index 433c9ab..247c945 100644
--- a/src/system/runtime_loader/elf_symbol_lookup.h
+++ b/src/system/runtime_loader/elf_symbol_lookup.h
@@ -58,7 +58,7 @@ struct SymbolLookupInfo {
struct SymbolLookupCache {
SymbolLookupCache(image_t* image)
:
- fTableSize(image->symhash[1]),
+ fTableSize(image->symhash != NULL ? image->symhash[1] : 0),
fValues(NULL),
fDSOs(NULL),
fValuesResolved(NULL)


Other related posts:

  • » [haiku-commits] haiku: hrev49728 - src/system/runtime_loader headers/private/system - pulkomandy