util/xcompile: Fix compiler detection on newer Linux distros

Switch to using `objdump -f`, which consistently prints the line
"file format <format>" across modern binutils versions, and extract
the architecture format from that output. This restores correct
toolchain detection on Ubuntu 25.10 and other systems with binutils
≥ 2.43, without breakng older versions.

Before:
    DEBUG: obj_type:
    /tmp/temp.rrDQ8i.o:     file format elf64-x86-64
    DEBUG: obj_arch:

After:
    DEBUG: obj_type:
    /tmp/temp.8GsK08.o:     file format elf64-x86-64
    architecture: i386:x86-64, flags 0x00000000:

    start address 0x0000000000000000
    DEBUG: obj_arch: elf64-x86-64

Change-Id: Ic09304f9e81580bbe1c0bb4910c0cc534d3d2816
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/89643
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
This commit is contained in:
Sean Rhodes 2025-10-20 10:19:01 +01:00
commit d7f427a7d2

View file

@ -155,8 +155,8 @@ testas() {
2>/dev/null || return 1
# Check output content type.
local obj_type="$(LANG=C LC_ALL='' "${gccprefix}"objdump -p "$obj_file" 2>/dev/null)"
local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')"
local obj_type="$(LANG=C LC_ALL='' "${gccprefix}"objdump -f "$obj_file" 2>/dev/null)"
local obj_arch="$(printf '%s\n' "$obj_type" | sed -n 's/.*file format \([a-z0-9-]*\).*/\1/p')"
[ "$obj_arch" = "$full_arch" ] || return 1
unset ASFLAGS LDFLAGS