Index: exeinfo.pp
===================================================================
--- exeinfo.pp	(revision 9869)
+++ exeinfo.pp	(working copy)
@@ -76,6 +76,10 @@
   {$DEFINE EMX}
 {$ENDIF OS2}
 
+{$ifdef BEOS}
+  {$define ELF32}
+{$endif BEOS}
+
 {$ifdef netware}
 
 const SIZE_OF_NLM_INTERNAL_FIXED_HEADER = 130;
@@ -832,100 +836,20 @@
 
 function get_next_image_info(team: team_id; var cookie:longint; var info:image_info; size: size_t) : status_t;cdecl; external 'root' name '_get_next_image_info';
 
-function LoadElf32Beos:boolean;
-type
-  telf32header=packed record
-      magic0123         : longint;
-      file_class        : byte;
-      data_encoding     : byte;
-      file_version      : byte;
-      padding           : array[$07..$0f] of byte;
-      e_type            : word;
-      e_machine         : word;
-      e_version         : longword;
-      e_entry           : longword;                  // entrypoint
-      e_phoff           : longword;                  // program header offset
-      e_shoff           : longword;                  // sections header offset
-      e_flags           : longword;
-      e_ehsize          : word;             // elf header size in bytes
-      e_phentsize       : word;             // size of an entry in the program header array
-      e_phnum           : word;             // 0..e_phnum-1 of entrys
-      e_shentsize       : word;             // size of an entry in sections header array
-      e_shnum           : word;             // 0..e_shnum-1 of entrys
-      e_shstrndx        : word;             // index of string section header
-  end;
-  telf32sechdr=packed record
-      sh_name           : longword;
-      sh_type           : longword;
-      sh_flags          : longword;
-      sh_addr           : longword;
-      sh_offset         : longword;
-      sh_size           : longword;
-      sh_link           : longword;
-      sh_info           : longword;
-      sh_addralign      : longword;
-      sh_entsize        : longword;
-    end;
+function OpenElf32Beos(var e:TExeFile):boolean;
 var
-  elfheader : telf32header;
-  elfsec    : telf32sechdr;
-  secnames  : array[0..255] of char;
-  pname     : pchar;
-  i : longint;
   cookie    : longint;
   info      : image_info;
-  result    : status_t;
 begin
+  // The only BeOS specific part is setting the processaddress
   cookie := 0;
   fillchar(info, sizeof(image_info), 0);
   get_next_image_info(0,cookie,info,sizeof(info));
   if (info._type = B_APP_IMAGE) then
-     processaddress := cardinal(info.text)
+     e.processaddress := cardinal(info.text)
   else
-     processaddress := 0;
-  LoadElf32Beos:=false;
-  stabofs:=-1;
-  stabstrofs:=-1;
-  { read and check header }
-  if E.Size<sizeof(telf32header) then
-   exit;
-  blockread(f,elfheader,sizeof(telf32header));
-{$ifdef ENDIAN_LITTLE}
- if elfheader.magic0123<>$464c457f then
-   exit;
-{$endif ENDIAN_LITTLE}
-{$ifdef ENDIAN_BIG}
- if elfheader.magic0123<>$7f454c46 then
-   exit;
-{$endif ENDIAN_BIG}
-  if elfheader.e_shentsize<>sizeof(telf32sechdr) then
-   exit;
-  { read section names }
-  seek(f,elfheader.e_shoff+elfheader.e_shstrndx*cardinal(sizeof(telf32sechdr)));
-  blockread(f,elfsec,sizeof(telf32sechdr));
-  seek(f,elfsec.sh_offset);
-  blockread(f,secnames,sizeof(secnames));
-  { read section info }
-  seek(f,elfheader.e_shoff);
-  for i:=1to elfheader.e_shnum do
-   begin
-     blockread(f,elfsec,sizeof(telf32sechdr));
-     pname:=@secnames[elfsec.sh_name];
-     if (pname[4]='b') and
-        (pname[1]='s') and
-        (pname[2]='t') then
-      begin
-        if (pname[5]='s') and
-           (pname[6]='t') then
-         stabstrofs:=elfsec.sh_offset
-        else
-         begin
-           stabofs:=elfsec.sh_offset;
-           stabcnt:=elfsec.sh_size div sizeof(tstab);
-         end;
-      end;
-   end;
-  LoadElf32Beos:=(stabofs<>-1) and (stabstrofs<>-1);
+     e.processaddress := 0;
+  Result := OpenElf(e);
 end;
 {$endif beos}
 
@@ -1094,14 +1018,15 @@
      openproc : @OpenPePlusCoff;
      findproc : @FindSectionPeCoff;
 {$endif PE32PLUS}
-{$if defined(ELF32) or defined(ELF64)}
+{$ifdef Beos}
+     openproc : @OpenElf32Beos;
+     findproc : @FindSectionElf;
+{$else}
+  {$if defined(ELF32) or defined(ELF64)}
      openproc : @OpenElf;
      findproc : @FindSectionElf;
+  {$endif}
 {$endif}
-{$ifdef Beos}
-     openproc : @OpenElf32Beos;
-     findproc : @FindSectionElf32Beos;
-{$endif}
 {$ifdef darwin}
      openproc : @OpenMachO32PPC;
      findproc : @FindSectionMachO32PPC;
