Page MenuHomeFreeBSD

libcompat: build 32-bit rtld and ldd as part of "everything"
ClosedPublic

Authored by brooks on Nov 6 2019, 12:38 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 6, 7:18 AM
Unknown Object (File)
Feb 9 2024, 9:50 AM
Unknown Object (File)
Dec 25 2023, 1:48 PM
Unknown Object (File)
Dec 25 2023, 1:48 PM
Unknown Object (File)
Dec 25 2023, 1:48 PM
Unknown Object (File)
Dec 25 2023, 1:48 PM
Unknown Object (File)
Dec 24 2023, 2:51 AM
Unknown Object (File)
Dec 23 2023, 12:36 AM

Details

Summary

Alter bsd.compat.mk to set MACHINE and MACHINE_ARCH when included
directly so MD paths in Makefiles work. In the process centralize
setting them in LIBCOMPATWMAKEENV.

Alter .PATH and CFLAGS settings in work when the Makefile is included.

While here only support LIB32 on supported platforms rather than always enabling it and requiring users of MK_LIB32 to filter based TARGET/MACHINE_ARCH.

The net effect of this change is to make Makefile.libcompat only build
compatability libraries.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I've now testing this in an amd64 VM with i386 binaries so it's ready for review.

If this permits easily doing something like 'make buildenv; cd rtld-elf32; make' then this really will be nicer than our current approach.

I do wish there was a way to avoid listing the same set of archs for ldd32 and rtld-elf32. Like if bsd.compat.mk could define some kind of 'supported ABIs' we could test against. OTOH, it might be sufficient to just depend on the MK_LIB32 setting since it will be off on unsupported archs and drop the arch tests completely?

I do not quite understand how even ld-elf32.so.1 can be built during non-compat build, not to mention normal binaries. For rtld, we need some object files from libc build. For binaries, we need libc.so.7 to link with. So how this stuff would work now ?

It is interesting that ldd32 actually does not need to be 32bit binary, except to handle 32bit dsos.

In D22251#486698, @kib wrote:

I do not quite understand how even ld-elf32.so.1 can be built during non-compat build, not to mention normal binaries. For rtld, we need some object files from libc build. For binaries, we need libc.so.7 to link with. So how this stuff would work now ?

NEED_COMPAT=32
.include <bsd.compat.mk>

Causes CFLAGS to include -m32, the appropriate sysroot, etc just as if building as part of the compat build. See rS353592, rS353593, rS353594, rS353595, rS353597, rS354227 for details.

In D22251#486697, @jhb wrote:

If this permits easily doing something like 'make buildenv; cd rtld-elf32; make' then this really will be nicer than our current approach.

It does, that's how I did my initial testing.

I do wish there was a way to avoid listing the same set of archs for ldd32 and rtld-elf32. Like if bsd.compat.mk could define some kind of 'supported ABIs' we could test against. OTOH, it might be sufficient to just depend on the MK_LIB32 setting since it will be off on unsupported archs and drop the arch tests completely?

Yeah, that's lame. I'll work up a fix (right now MK_LIB32=yes by default and that should change).

  • Default LIB32 to on where supported and mark broken elsewhere.
This revision is now accepted and ready to land.Nov 6 2019, 11:52 PM
In D22251#486698, @kib wrote:

I do not quite understand how even ld-elf32.so.1 can be built during non-compat build, not to mention normal binaries. For rtld, we need some object files from libc build. For binaries, we need libc.so.7 to link with. So how this stuff would work now ?

NEED_COMPAT=32
.include <bsd.compat.mk>

Causes CFLAGS to include -m32, the appropriate sysroot, etc just as if building as part of the compat build. See rS353592, rS353593, rS353594, rS353595, rS353597, rS354227 for details.

I do not know our build to usefully comment on the change. But, could you please show me both the linking command line invocation for linking of ld-elf32, and the output from file on the resulting interpreter ?

link command:

cc -target x86_64-unknown-freebsd13.0 --sysroot=/home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/tmp -B/home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/tmp/usr/bin -O2 -pipe -DCOMPAT_32BIT -march=i686 -mmmx -msse -msse2 -target x86_64-unknown-freebsd13.0 -m32 -L/home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/obj-lib32/tmp/usr/lib32 --sysroot=/home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/obj-lib32/tmp -B/home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/obj-lib32/tmp/usr/lib32 -Wall -DFREEBSD_ELF -DIN_RTLD -ffreestanding -I/home/bed22/git/freebsd/lib/csu/common -I/home/bed22/git/freebsd/libexec/rtld-elf/i386 -I/home/bed22/git/freebsd/libexec/rtld-elf -fpic -DPIC -fvisibility=hidden -I/home/bed22/git/freebsd/libexec/rtld-elf/rtld-libc -mno-mmx -mno-sse -mno-avx -mno-avx2 -msoft-float -g -std=gnu99 -Wno-format-zero-length -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wold-style-definition -Wno-pointer-sign -Wformat=2 -Wno-format-extra-args -Werror -Wmissing-variable-declarations -Wthread-safety -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Qunused-arguments  -nostdlib -e .rtld_start -shared -Wl,-Bsymbolic -Wl,-z,defs -Wl,--version-script=Version.map   -o ld-elf32.so.1.full rtld_start.o reloc.o rtld.o rtld_lock.o rtld_malloc.o rtld_printf.o map_object.o xmalloc.o debug.o libmap.o opendir.o closedir.o readdir.o telldir.o rtld_libc.o reallocf.o realpath.o getenv.o merge.o reallocarray.o errlst.o getcwd.o getprogname.o raise.o sigsetops.o sysctlnametomib.o __xuname.o  /home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/libexec/rtld-elf32/rtld_libc.a

file output:

~/git/freebsd/libexec/rtld-elf32 buildenv> file `make -V .OBJDIR`/ld-elf32.so.1
/home/bed22/obj/home/bed22/git/freebsd/amd64.amd64/libexec/rtld-elf32/ld-elf32.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (FreeBSD), dynamically linked, not stripped