diff mbox series

insane.bbclass: use HOST_ARCH to check for 32-bit symbols

Message ID 20240523125441.45922-1-emil.kronborg@protonmail.com
State New
Headers show
Series insane.bbclass: use HOST_ARCH to check for 32-bit symbols | expand

Commit Message

Emil Kronborg May 23, 2024, 12:54 p.m. UTC
Using OVERRIDES in the check generates false positives in some
scenarios, for example when building binaries for an SDK supposed to run
on a 64-bit host. Therefore, it is more correct to use HOST_ARCH for the
check instead.

    $ bitbake -c do_package_qa gcc-cross-canadian-arm
    (...)
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'localtime'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'fcntl'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'lstat'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'wait4'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'gettimeofday'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'stat'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'fstat'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'ioctl'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'time'
    /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'gmtime'
    Suppress with INSANE_SKIP = "32bit-time"

Signed-off-by: Emil Kronborg <emil.kronborg@protonmail.com>
---
 meta/classes-global/insane.bbclass | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)


base-commit: 50f78cb9de68cd4317f34321dfdb06d72ce5d3c6

Comments

Richard Purdie May 23, 2024, 1:39 p.m. UTC | #1
On Thu, 2024-05-23 at 12:54 +0000, Emil Kronborg via lists.openembedded.org wrote:
> Using OVERRIDES in the check generates false positives in some
> scenarios, for example when building binaries for an SDK supposed to run
> on a 64-bit host. Therefore, it is more correct to use HOST_ARCH for the
> check instead.
> 
>     $ bitbake -c do_package_qa gcc-cross-canadian-arm
>     (...)
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'localtime'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'fcntl'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'lstat'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'wait4'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'gettimeofday'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'stat'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'fstat'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'ioctl'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'time'
>     /usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++ uses 32-bit api 'gmtime'
>     Suppress with INSANE_SKIP = "32bit-time"
> 
> Signed-off-by: Emil Kronborg <emil.kronborg@protonmail.com>
> ---
>  meta/classes-global/insane.bbclass | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/meta/classes-global/insane.bbclass b/meta/classes-global/insane.bbclass
> index 99736830b9a8..bd2328601676 100644
> --- a/meta/classes-global/insane.bbclass
> +++ b/meta/classes-global/insane.bbclass
> @@ -515,8 +515,7 @@ def check_32bit_symbols(path, packagename, d, elf, messages):
>      Check that ELF files do not use any 32 bit time APIs from glibc.
>      """
>      thirtytwo_bit_time_archs = {'arm','armeb','mipsarcho32','powerpc','x86'}
> -    overrides = set(d.getVar('OVERRIDES').split(':'))
> -    if not (thirtytwo_bit_time_archs & overrides):
> +    if d.getVar('HOST_ARCH') not in thirtytwo_bit_time_archs:
>          return
> 

This is not correct, e.g. HOST_ARCH does not always equal "x86" for 32
bit x86 builds.

$ MACHINE=qemux86 bitbake -e | grep ^OVERRIDES= -C 2
# pre-expansion value:
#   "${TARGET_OS}:${TRANSLATED_TARGET_ARCH}:pn-${PN}:layer-${FILE_LAYERNAME}:${MACHINEOVERRIDES}:${DISTROOVERRIDES}:${CLASSOVERRIDE}${LIBCOVERRIDE}:forcevariable"
OVERRIDES="linux:i686:pn-defaultpkgname:layer-config:x86:qemuall:qemux86:poky:poky-altcfg:class-target:libc-glibc:forcevariable"

i.e. the x86 comes from MACHINEOVERRIDES.

Cheers,

Richard
Emil Kronborg May 24, 2024, 7:46 a.m. UTC | #2
On Thu, May 23, 2024 at 14:39 GMT, Richard Purdie wrote:
> This is not correct, e.g. HOST_ARCH does not always equal "x86" for 32
> bit x86 builds.
> 
> $ MACHINE=qemux86 bitbake -e | grep ^OVERRIDES= -C 2
> # pre-expansion value:
> #   "${TARGET_OS}:${TRANSLATED_TARGET_ARCH}:pn-${PN}:layer-${FILE_LAYERNAME}:${MACHINEOVERRIDES}:${DISTROOVERRIDES}:${CLASSOVERRIDE}${LIBCOVERRIDE}:forcevariable"
> OVERRIDES="linux:i686:pn-defaultpkgname:layer-config:x86:qemuall:qemux86:poky:poky-altcfg:class-target:libc-glibc:forcevariable"
> 
> i.e. the x86 comes from MACHINEOVERRIDES.

There is obviously a problem when building binaries for an SDK and using
OVERRIDES for the check. To me, HOST_ARCH looks most correct, but if it
misses some cases, it should not be used as a one-to-one replacement for
OVERRIDES. Is there some proper way in BitBake to catch all 32-bit
architectures? If not, would adding i686, and potentially other missing
names, to the list of 32-bit time architectures, i.e
thirtytwo_bit_time_archs, be feasible?
Alexander Kanavin May 24, 2024, 7:49 a.m. UTC | #3
On Fri, 24 May 2024 at 09:47, Emil Kronborg via lists.openembedded.org
<emil.kronborg=protonmail.com@lists.openembedded.org> wrote:
> There is obviously a problem when building binaries for an SDK and using
> OVERRIDES for the check. To me, HOST_ARCH looks most correct, but if it
> misses some cases, it should not be used as a one-to-one replacement for
> OVERRIDES. Is there some proper way in BitBake to catch all 32-bit
> architectures? If not, would adding i686, and potentially other missing
> names, to the list of 32-bit time architectures, i.e
> thirtytwo_bit_time_archs, be feasible?

I vaguely remember that at some point I ran 'bitbake -e recipe'
against qemux86 machine to study that question, and looked through all
related variables, and couldn't find anything better. But you're
welcome to try that as well.

Alex
Emil Kronborg May 27, 2024, 10:19 a.m. UTC | #4
On Fri, May 24, 2024 at 09:49 GMT, Alexander Kanavin wrote:
> I vaguely remember that at some point I ran 'bitbake -e recipe'
> against qemux86 machine to study that question, and looked through all
> related variables, and couldn't find anything better. But you're
> welcome to try that as well.

For my specific example, I still believe it is more accurate to use
HOST_ARCH and add "i686" to thirtytwo_bit_time_archs. This setup does
not generate false positives and also works for qemux86. However, it
will not necessarily work for other cases. To make it more general, I
think some of the architectures from meta/lib/oe/elf.py can be added to
thirtytwo_bit_time_archs. When comparing this with elf.py, I noticed
some inconsistency. For example, both "arm" and "armb" are defined,
while only "x86" is defined. Shouldn't the latter substituted with
"i386", "i486", "i586" and "i686"? Also, shouldn't "mipsarcho32"
correspond to the entries in elf.py? I'm unsure which ones exactly
though.
diff mbox series

Patch

diff --git a/meta/classes-global/insane.bbclass b/meta/classes-global/insane.bbclass
index 99736830b9a8..bd2328601676 100644
--- a/meta/classes-global/insane.bbclass
+++ b/meta/classes-global/insane.bbclass
@@ -515,8 +515,7 @@  def check_32bit_symbols(path, packagename, d, elf, messages):
     Check that ELF files do not use any 32 bit time APIs from glibc.
     """
     thirtytwo_bit_time_archs = {'arm','armeb','mipsarcho32','powerpc','x86'}
-    overrides = set(d.getVar('OVERRIDES').split(':'))
-    if not (thirtytwo_bit_time_archs & overrides):
+    if d.getVar('HOST_ARCH') not in thirtytwo_bit_time_archs:
         return
 
     import re