[haiku-bugs] Re: [Haiku] #8520: runtime loader should check elf headers for things like architecture.

  • From: "bonefish" <trac@xxxxxxxxxxxx>
  • Date: Fri, 04 May 2012 21:11:53 -0000

#8520: runtime loader should check elf headers for things like architecture.
-------------------------------------+----------------------------
   Reporter:  kallisti5              |      Owner:  bonefish
       Type:  enhancement            |     Status:  new
   Priority:  normal                 |  Milestone:  R1/alpha4
  Component:  System/runtime_loader  |    Version:  R1/Development
 Resolution:                         |   Keywords:
 Blocked By:                         |   Blocking:
Has a Patch:  1                      |   Platform:  All
-------------------------------------+----------------------------

Comment (by bonefish):

 @kallisti5: The check should not only be done in `test_executable()`. That
 function is called for an executable that is asked to be executed. It is
 not called for libraries or add-ons being loaded. So a check in
 `parse_elf_header()` is required as well.

 Regarding the patch:
  - The new error macro definitions should be appended to the block for the
 runtime loader errors, continuing the sequence.
  - I don't see what error condition `B_BAD_IMAGE_PLATFORM` would indicate.
  - For `B_BAD_IMAGE_ARCHITECTURE` I would find "MISMATCHING" instead of
 "BAD" more fitting. I'd also drop the "IMAGE".
  - I doubt `test_architecture()` even compiles. It declares `char
 name[128]`, but assigns string literals to the variable.
  - I would organize the architecture check differently: In some header
 define a macro `ELF_MACHINE` for the expected ELF machine via #ifdef
 chain. The check in `test_architecture()` becomes `elfMachine ==
 ELF_MACHINE`. The debug output is not needed IMO, so `test_architecture()`
 becomes superfluous; the check can be inlined in both `test_executable()`
 and `parse_elf_header()`.

 Regarding your TODO question: No, the i386/x86_64 check cannot be done in
 the runtime loader. The kernel already needs to load the respective
 runtime loader matching the architecture.

 @X512: No, it isn't that simple. At some points (whether it is shared
 object boundaries or the kernel interface and client-server protocols) the
 emulated program needs to interface with the native system. At these
 points a translation has to happen that qemu cannot possibly know about.
 E.g. a C structure that is passed to the kernel doesn't necessarily have
 the same layout for all architectures (certain datatypes may or may not
 change width depending on the architecture). The information for such a
 conversion is not present in the object code.

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/8520#comment:11>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: