Re: [PATCH 3/4] kbuild: spilt cc-option and friends to scripts/Makefile.compiler

From: Masahiro Yamada
Date: Thu Apr 15 2021 - 03:35:10 EST


On Tue, Apr 13, 2021 at 10:11 PM Christian Borntraeger
<borntraeger@xxxxxxxxxx> wrote:
>
>
>
> On 13.04.21 14:51, Janosch Frank wrote:
> > On 2/28/21 7:10 AM, Masahiro Yamada wrote:
> >> scripts/Kbuild.include is included everywhere, but macros such as
> >> cc-option are needed by build targets only.
> >>
> >> For example, when 'make clean' traverses the tree, it does not need
> >> to evaluate $(call cc-option,).
> >>
> >> Split cc-option, ld-option, etc. to scripts/Makefile.compiler, which
> >> is only included from the top Makefile and scripts/Makefile.build.
> >>
> >> Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
> >
> > This commit broke the KVM selftest compilation under s390 in linux-next
> > for me. Funny enough the compilation is only broken on Ubuntu, under
> > Fedora the test fails with an assertion.
> >
> > FEDORA:
> > [root@fedora kvm]# ./set_memory_region_test
> > Allowed number of memory slots: 32767
> > ==== Test Assertion Failure ====
> > lib/kvm_util.c:142: vm->fd >= 0
> > pid=1541645 tid=1541645 - Invalid argument
> > 1 0x0000000001002f4b: vm_open at kvm_util.c:142
> > 2 (inlined by) vm_create at kvm_util.c:258
> > 3 0x00000000010015ef: test_add_max_memory_regions at
> > set_memory_region_test.c:351
> > 4 (inlined by) main at set_memory_region_test.c:397
> > 5 0x000003ffa3d2bb89: ?? ??:0
> > 6 0x00000000010017ad: .annobin_abi_note.c.hot at crt1.o:?
> > KVM_CREATE_VM ioctl failed, rc: -1 errno: 22
> >
> >
> > Ubuntu:
> > make[1]: Leaving directory '/mnt/dev/linux'
> > gcc -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99
> > -fno-stack-protector -fno-PIE -I../../../../tools/include
> > -I../../../../tools/arch/s390/include -I../../../../usr/include/
> > -Iinclude -Ilib -Iinclude/s390x -I.. -c lib/sparsebit.c -o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/sparsebit.o
> > gcc -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99
> > -fno-stack-protector -fno-PIE -I../../../../tools/include
> > -I../../../../tools/arch/s390/include -I../../../../usr/include/
> > -Iinclude -Ilib -Iinclude/s390x -I.. -c lib/kvm_util.c -o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/kvm_util.o
> > gcc -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99
> > -fno-stack-protector -fno-PIE -I../../../../tools/include
> > -I../../../../tools/arch/s390/include -I../../../../usr/include/
> > -Iinclude -Ilib/s390x -Iinclude/s390x -I.. -c
> > lib/s390x/diag318_test_handler.c -o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/s390x/diag318_test_handler.o
> > ar crs /mnt/dev/linux/tools/testing/selftests/kvm/libkvm.a
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/assert.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/elf.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/io.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/kvm_util.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/sparsebit.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/test_util.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/guest_modes.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/perf_test_util.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/s390x/processor.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/s390x/ucall.o
> > /mnt/dev/linux/tools/testing/selftests/kvm/lib/s390x/diag318_test_handler.o
> > gcc -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99
> > -fno-stack-protector -fno-PIE -I../../../../tools/include
> > -I../../../../tools/arch/s390/include -I../../../../usr/include/
> > -Iinclude -Is390x -Iinclude/s390x -I.. -pthread s390x/memop.c
> > /mnt/dev/linux/tools/testing/selftests/kvm/libkvm.a -o
> > /mnt/dev/linux/tools/testing/selftests/kvm/s390x/memop
> > /usr/bin/ld: /tmp/ccFU8WYF.o: `stdout@@GLIBC_2.2' non-PLT reloc for
> > symbol defined in shared library and accessed from executable (rebuild
> > file with -fPIC ?)
> > /usr/bin/ld: final link failed: bad value
> > collect2: error: ld returned 1 exit status
> > make: *** [../lib.mk:139:
> > /mnt/dev/linux/tools/testing/selftests/kvm/s390x/memop] Error 1
> >
>
>
>
> It looks like that from tools/testing/selftests/kvm/Makefile
> additional linker flags are being ignored with this patch.
>
> no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
> $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
>
> # On s390, build the testcases KVM-enabled
> pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
> $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
>
>
> LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
>


Thanks.

I will separate Kbuild and the tool build system.
https://patchwork.kernel.org/project/linux-kbuild/patch/20210415072700.147125-2-masahiroy@xxxxxxxxxx/

I do not want to be bothered by the can of worms.





--
Best Regards
Masahiro Yamada