Re: binutils and llvm for cross-building
Hi Dima,
On Fri, Sep 05, 2025 at 02:19:37PM -0700, Dima Kogan wrote:
> - llvm-objcopy:amd64 actually appears to work on arm64 binaries. Can
> this be relied-upon?
Kinda yes. I guess llvm-objcopy automatically detects the input format
and adapts. To be safe, pass --target as indicated in my previous mail.
In any case, one usually does not enable or disable targets while
building llvm and rather leaves them all enabled, so you may typically
assume that llvm can target anything (even when it practically cannot
yet).
> - The GNU aarch64-linux-gnu-objcopy tool works too, but objcopy from
> binutils:amd64 does not (unlike nm from binutils:amd64, which does
> work)
Yes, that's one of those tools that's specific to an architecture and
properly needs to be prefixed.
> As upstream, how do I write Makefiles that work for different distros
> and for both native and cross-building in Debian? I can do this:
>
>
> DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE 2>/dev/null)
> tst.o: tst.c
> ....
> $(if $(DEB_HOST_GNU_TYPE),$(DEB_HOST_GNU_TYPE)-)objcopy ...
>
> But that's a mouthful. Is there a better way?
There are two good ways. One is making all of those tools substitutable
independently.
OBJCOPY ?= objcopy
...
...:
$(OBJCOPY) ...
You may optionally support the prefix separately.
CROSS_COMPILE ?=
ifeq ($(origin CC),default)
CC := $(CROSS_COMPILE)$(CC)
endif
OBJCOPY ?= $(CROSS_COMPILE)objcopy
This way, a user may choose each tool individually or set
CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)- to prefix them all. dh_auto_build
for the makefile buildsystem does the former (set all the tools
individually).
Helmut
Reply to: