Skip to content

Commit 03b72d4

Browse files
committed
fbc: read objinfo for elf format files on arm32 and arm64 (aarch64) to allow automatic options and linking of libraries
(cherry picked from commit b54cd3c)
1 parent 978c30e commit 03b72d4

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Version 1.07.2
1818
- sf.net #925: CSIGN/CUNSG preserve size when converting pointers on 64-bit and implict conversion of STEP value in FOR...NEXT statement
1919
- github #122: gfxlib2: linux GFX_NO_FRAME + GFX_OPENGL freezing at exit due to a dead lock between exit routines
2020
- use the multi-byte & wide character functions wctombs() & mbtowcs() when converting between string and wstring (Skyfish)
21+
- read objinfo for elf format files on arm32 and arm64 (aarch64) to allow automatic options and linking of libraries
2122

2223

2324
Version 1.07.1

src/compiler/objinfo.bas

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
'' hLoadFbctinfFromObj():
8282
'' reads the currently loaded object file,
8383
'' using either the COFF (Win32, DOS) or ELF32 (Linux, *BSD) format.
84+
'' ELF32 (linux-arm) or ELF64 (linux-aarch64)
8485
'' looks for the .fbctinf section,
8586
'' and if found, parses its content, and tells the frontend about the
8687
'' found libraries etc. by using the callbacks.
@@ -166,12 +167,14 @@ end type
166167
dim shared as ubyte elfmagic(0 to 15) = _
167168
{ _
168169
&h7f, &h45, &h4c, &h46, 0, &h01, _ '' index 4 is set to 1 (32bit) or 2 (64bit)
169-
&h01, &h00, &h00, &h00, &h00, &h00 _
170+
&h01, &h00, &h00, &h00, &h00, &h00 _ '' index 12 is set to machine
170171
}
171172

172173
const ET_REL = 1
173174
const EM_386 = 3
174-
const EM_X86_64 = 62
175+
const EM_X86_64 = &h3e
176+
const EM_ARM32 = &h28
177+
const EM_AARCH64 = &hb7
175178

176179
'' ELF section headers
177180
type ELF32_SH field = 1
@@ -205,7 +208,7 @@ end type
205208
'' different field offsets and sizes), and there are a few constant values that
206209
'' are different too.
207210

208-
#macro ELFLOADINGCODE(ELF_H, ELF_SH, ELF_MAGIC_4, ELF_MACHINE)
211+
#macro ELFLOADINGCODE(ELF_H, ELF_SH, ELF_MAGIC_4)
209212

210213
private function hCheck##ELF_SH _
211214
( _
@@ -271,7 +274,7 @@ private function hGetSectionName##ELF_SH _
271274
function = @sectionname
272275
end function
273276

274-
private sub hLoadFbctinfFrom##ELF_H( )
277+
private sub hLoadFbctinfFrom##ELF_H( byval ELF_MACHINE as integer )
275278
dim as ELF_H ptr h = any
276279
dim as ELF_SH ptr sh = any, nametb = any
277280
dim as zstring ptr sectionname = any
@@ -306,7 +309,7 @@ private sub hLoadFbctinfFrom##ELF_H( )
306309
exit sub
307310
end if
308311

309-
'' x86/x86_64?
312+
'' x86/x86_64/arm/aarch64?
310313
if( h->e_machine <> ELF_MACHINE ) then
311314
INFO( "elf: machine mismatch" )
312315
exit sub
@@ -364,8 +367,8 @@ end sub
364367

365368
#endmacro
366369

367-
ELFLOADINGCODE( ELF32_H, ELF32_SH, 1, EM_386 )
368-
ELFLOADINGCODE( ELF64_H, ELF64_SH, 2, EM_X86_64 )
370+
ELFLOADINGCODE( ELF32_H, ELF32_SH, 1 )
371+
ELFLOADINGCODE( ELF64_H, ELF64_SH, 2 )
369372

370373
'' COFF main header
371374
type COFF_H field = 1
@@ -625,10 +628,16 @@ private sub hLoadFbctinfFromObj( )
625628
select case( fbGetCpuFamily( ) )
626629
case FB_CPUFAMILY_X86_64
627630
INFO( "reading x86-64 ELF: " + parser.filename )
628-
hLoadFbctinfFromELF64_H( )
631+
hLoadFbctinfFromELF64_H( EM_X86_64 )
629632
case FB_CPUFAMILY_X86
630633
INFO( "reading i386 ELF: " + parser.filename )
631-
hLoadFbctinfFromELF32_H( )
634+
hLoadFbctinfFromELF32_H( EM_386 )
635+
case FB_CPUFAMILY_AARCH64
636+
INFO( "reading aarch64 ELF: " + parser.filename )
637+
hLoadFbctinfFromELF64_H( EM_AARCH64 )
638+
case FB_CPUFAMILY_ARM
639+
INFO( "reading arm32 ELF: " + parser.filename )
640+
hLoadFbctinfFromELF32_H( EM_ARM32 )
632641
end select
633642
end if
634643

0 commit comments

Comments
 (0)