Skip to content

Commit

Permalink
Override the default arm cpu type for android-arm target to be armv5t…
Browse files Browse the repository at this point in the history
…e instead of armv7a, regardless of the format of the -target arg.

I guess armv7a is still a reasonable default as it's common these days, and
seems to be required by most arm ports of linux distros, all android 4.3+
phones, and is on RPi2+.
  • Loading branch information
rversteegen authored and jayrm committed Jan 2, 2024
1 parent 985ed3e commit 21b37b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/compiler/fb.bas
Expand Up @@ -985,9 +985,14 @@ function fbIdentifyCpuFamily( byref cpufamilyid as string ) as integer
function = -1
end function

function fbCpuTypeFromCpuFamilyId( byref cpufamilyid as string ) as integer
function fbDefaultCpuTypeFromCpuFamilyId( byval os as integer, byref cpufamilyid as string ) as integer
var cpufamily = fbIdentifyCpuFamily( cpufamilyid )
if( cpufamily >= 0 ) then
if( (os = FB_COMPTARGET_ANDROID) and _
(cpufamily = FB_CPUFAMILY_ARM) ) then
'' Special case: our default arm cpu should be armv5te on android
return FB_CPUTYPE_ARMV5TE
end if
return cpufamilyinfo(cpufamily).defaultcputype
end if
function = -1
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/fb.bi
Expand Up @@ -431,6 +431,7 @@ const FB_DEFAULT_CPUTYPE_X86 = FB_CPUTYPE_686
const FB_DEFAULT_CPUTYPE_X86_64 = FB_CPUTYPE_X86_64

'' default ARM CPU
'' A reasonable default for PCs, but on android is overridden to FB_CPUTYPE_ARMV5TE
#ifdef BUILD_FB_DEFAULT_CPUTYPE_ARM
const FB_DEFAULT_CPUTYPE_ARM = BUILD_FB_DEFAULT_CPUTYPE_ARM
#else
Expand Down Expand Up @@ -550,8 +551,8 @@ declare sub fbOverrideFilename(byval filename as zstring ptr)
declare function fbGetTargetId( ) as string
declare function fbGetHostId( ) as string
declare function fbIdentifyOs( byref osid as string ) as integer
declare function fbIdentifyCpuFamily( byref osid as string ) as integer
declare function fbCpuTypeFromCpuFamilyId( byref cpufamilyid as string ) as integer
declare function fbIdentifyCpuFamily( byref cpufamilyid as string ) as integer
declare function fbDefaultCpuTypeFromCpuFamilyId( byval os as integer, byref cpufamilyid as string ) as integer
declare function fbGetGccArch( ) as zstring ptr
declare function fbGetFbcArch( ) as zstring ptr
declare function fbIs64Bit( ) as integer
Expand Down
10 changes: 8 additions & 2 deletions src/compiler/fbc.bas
Expand Up @@ -1580,6 +1580,7 @@ private sub hParseGnuTriplet _
byref os as integer, _
byref cputype as integer _
)
dim arch as string

'' Search for OS, it be anywere in the triplet:
'' mingw32 -> mingw
Expand All @@ -1600,7 +1601,7 @@ private sub hParseGnuTriplet _
'' If the triplet has at least two components (<arch>-<...>),
'' extract the first (the architecture) and try to identify it.
if( separator > 0 ) then
var arch = left( arg, separator - 1 )
arch = left( arg, separator - 1 )
for i as integer = 0 to ubound( gnuarchmap )
if( arch = *gnuarchmap(i).gnuid ) then
cputype = gnuarchmap(i).cputype
Expand All @@ -1609,6 +1610,10 @@ private sub hParseGnuTriplet _
next
end if

'' Special case: our default arm cpu should be armv5te on android
if( (os = FB_COMPTARGET_ANDROID) and (arch = "arm") ) then
cputype = FB_CPUTYPE_ARMV5TE
end if
end sub

function fbCpuTypeFromGNUArchInfo( byref arch as string ) as integer
Expand Down Expand Up @@ -1728,7 +1733,7 @@ private sub hParseTargetArg _
var separator = instr( arg, "-" )
if( separator > 0 ) then
os = fbIdentifyOs( left( lcasearg, separator - 1 ) )
cputype = fbCpuTypeFromCpuFamilyId( right( lcasearg, len( lcasearg ) - separator ) )
cputype = fbDefaultCpuTypeFromCpuFamilyId( os, right( lcasearg, len( lcasearg ) - separator ) )

'' allow normalizing on gnu arch types to determine the standalone targetid
#ifdef ENABLE_STANDALONE
Expand Down Expand Up @@ -1920,6 +1925,7 @@ private sub handleOpt _
fbcAddObj( arg )

case OPT_ARCH
'' Set cputype later, so it overrides -target
fbc.cputype_is_native = (arg = "native")
fbc.cputype = fbIdentifyFbcArch( arg )
if( fbc.cputype < 0 ) then
Expand Down

0 comments on commit 21b37b3

Please sign in to comment.