Page MenuHomeFreeBSD

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

Authored by brooks on Wed, Nov 6, 12:38 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
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

brooks created this revision.Wed, Nov 6, 12:38 AM

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

brooks added a reviewer: jhb.Wed, Nov 6, 7:38 PM
jhb added a comment.Wed, Nov 6, 7:53 PM

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?

kib added a comment.Wed, Nov 6, 8:00 PM

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).

brooks updated this revision to Diff 64026.Wed, Nov 6, 11:07 PM
  • Default LIB32 to on where supported and mark broken elsewhere.
imp accepted this revision.Wed, Nov 6, 11:52 PM
This revision is now accepted and ready to land.Wed, Nov 6, 11:52 PM
kib added a comment.Thu, Nov 7, 3:06 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 ?

brooks added a comment.Thu, Nov 7, 4:15 PM

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
kib accepted this revision.Thu, Nov 7, 4:33 PM
brooks edited the summary of this revision. (Show Details)Thu, Nov 7, 4:42 PM
This revision was automatically updated to reflect the committed changes.