Skip to contentSkip to conversation

selftests/powerpc: Fix try-run when source tree is not writable

PATCH Applied Michael Ellerman 2 participants 2 messages Mar 27, 2020 – Apr 1, 2020

Subsystems (2)
lore
Share & tools
lore

Michael Ellerman

author reviewer
#0 lore raw

PATCH 1/1 selftests/powerpc: Fix try-run when source tree is not writable

We added a usage of try-run to pmu/ebb/Makefile to detect if the toolchain supported the -no-pie option.

This fails if we build out-of-tree and the source tree is not writable, as try-run tries to write its temporary files to the current directory. That leads to the -no-pie option being silently dropped, which leads to broken executables with some toolchains.

If we remove the redirect to /dev/null in try-run, we see the error:

make[3]: Entering directory '/linux/tools/testing/selftests/powerpc/pmu/ebb' /usr/bin/ld: cannot open output file .54.tmp: Read-only file system
collect2: error: ld returned 1 exit status
make[3]: Nothing to be done for 'all'.

And looking with strace we see it's trying to use a file that's in the source tree:

lstat("/linux/tools/testing/selftests/powerpc/pmu/ebb/.54.tmp", 0x7ffffc0f83c8)

We can fix it by setting TMPOUT to point to the $(OUTPUT) directory, and we can verify with strace it's now trying to write to the output directory:

lstat("/output/kselftest/powerpc/pmu/ebb/.54.tmp", 0x7fffd1bf6bf8)

And also see that the -no-pie option is now correctly detected.

Fixes 0695f8bca93e ("selftests/powerpc: Handle Makefile for unrecognized option")
---
 tools/testing/selftests/powerpc/pmu/ebb/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/powerpc/pmu/ebb/Makefile +1 -0
index 417306353e07..ca35dd8848b0 100644
@@ -7,6 +7,7 @@ include ../../../../../../scripts/Kbuild.include
 # The EBB handler is 64-bit code and everything links against it
 CFLAGS += -m64
 
+TMPOUT = $(OUTPUT)/
 # Toolchains may build PIE by default which breaks the assembly
 no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
         $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -no-pie -x c - -o "$$TMP", -no-pie)

base-commit: 11a48a5a18c63fd7621bb050228cebf13566e4d8
prerequisite-patch-id: e460261e180666bfb63bcd0cc554874d73c3b71f
prerequisite-patch-id: 67db368cfdf8d3aefd78f140420281f9b4b53e07
prerequisite-patch-id: cf5d957a366998b4a3ce70a79b6e969eb98fca7d
prerequisite-patch-id: 3ace935c6ae425ad635eb38f906e790c3c9bf41f

Signature · 1 line
2.25.1
#1 lore raw
Quoted 24 lines · Michael Ellerman

We added a usage of try-run to pmu/ebb/Makefile to detect if the toolchain supported the -no-pie option.

This fails if we build out-of-tree and the source tree is not writable, as try-run tries to write its temporary files to the current directory. That leads to the -no-pie option being silently dropped, which leads to broken executables with some toolchains.

If we remove the redirect to /dev/null in try-run, we see the error:

make[3]: Entering directory '/linux/tools/testing/selftests/powerpc/pmu/ebb' /usr/bin/ld: cannot open output file .54.tmp: Read-only file system
collect2: error: ld returned 1 exit status
make[3]: Nothing to be done for 'all'.

And looking with strace we see it's trying to use a file that's in the source tree:

lstat("/linux/tools/testing/selftests/powerpc/pmu/ebb/.54.tmp", 0x7ffffc0f83c8)

We can fix it by setting TMPOUT to point to the $(OUTPUT) directory, and we can verify with strace it's now trying to write to the output directory:

Quoted 7 lines

lstat("/output/kselftest/powerpc/pmu/ebb/.54.tmp", 0x7fffd1bf6bf8)

And also see that the -no-pie option is now correctly detected.

Fixes 0695f8bca93e ("selftests/powerpc: Handle Makefile for unrecognized option")

Applied to powerpc next.

https://git.kernel.org/powerpc/c/9686813f6e9d5568bc045de0be853411e44958c8

cheers