linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/exec: build with -fPIE instead of -pie, to make clang happy
@ 2024-05-04  2:23 John Hubbard
  2024-05-06 17:09 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: John Hubbard @ 2024-05-04  2:23 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Eric Biederman, Kees Cook, Muhammad Usama Anjum, Mark Brown,
	linux-mm, Valentin Obst, linux-kselftest, LKML, llvm,
	John Hubbard

clang doesn't deal well with "-pie -static": it warns that -pie is an
unused option here. Changing to "-fPIE -static" solves this problem for
clang, while keeping the gcc results identical.

The problem is visible when building via:

    make LLVM=1 -C tools/testing/selftests

Again: gcc 13 produces identical binaries for all of these programs,
both before and after this commit (using "-pie"), and after (using
"-fPIE").

Also, the runtime results are the same for both clang and gcc builds.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 tools/testing/selftests/exec/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
index fb4472ddffd8..b7b54d442378 100644
--- a/tools/testing/selftests/exec/Makefile
+++ b/tools/testing/selftests/exec/Makefile
@@ -29,8 +29,8 @@ $(OUTPUT)/execveat.denatured: $(OUTPUT)/execveat
 	cp $< $@
 	chmod -x $@
 $(OUTPUT)/load_address_4096: load_address.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000 -pie -static $< -o $@
+	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000 -fPIE -static $< -o $@
 $(OUTPUT)/load_address_2097152: load_address.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x200000 -pie -static $< -o $@
+	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x200000 -fPIE -static $< -o $@
 $(OUTPUT)/load_address_16777216: load_address.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000000 -pie -static $< -o $@
+	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000000 -fPIE -static $< -o $@

base-commit: ddb4c3f25b7b95df3d6932db0b379d768a6ebdf7
prerequisite-patch-id: b901ece2a5b78503e2fb5480f20e304d36a0ea27
-- 
2.45.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/exec: build with -fPIE instead of -pie, to make clang happy
  2024-05-04  2:23 [PATCH] selftests/exec: build with -fPIE instead of -pie, to make clang happy John Hubbard
@ 2024-05-06 17:09 ` Kees Cook
  2024-05-06 19:08   ` John Hubbard
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2024-05-06 17:09 UTC (permalink / raw)
  To: John Hubbard
  Cc: Shuah Khan, Eric Biederman, Muhammad Usama Anjum, Mark Brown,
	linux-mm, Valentin Obst, linux-kselftest, LKML, llvm

On Fri, May 03, 2024 at 07:23:01PM -0700, John Hubbard wrote:
> clang doesn't deal well with "-pie -static": it warns that -pie is an
> unused option here. Changing to "-fPIE -static" solves this problem for
> clang, while keeping the gcc results identical.
> 
> The problem is visible when building via:
> 
>     make LLVM=1 -C tools/testing/selftests
> 
> Again: gcc 13 produces identical binaries for all of these programs,
> both before and after this commit (using "-pie"), and after (using
> "-fPIE").
> 
> Also, the runtime results are the same for both clang and gcc builds.

Thanks for this! It got solved differently here:
https://lkml.kernel.org/r/20240416152831.3199999-1-usama.anjum@collabora.com

Does that work for you as well?

-Kees

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/exec: build with -fPIE instead of -pie, to make clang happy
  2024-05-06 17:09 ` Kees Cook
@ 2024-05-06 19:08   ` John Hubbard
  0 siblings, 0 replies; 3+ messages in thread
From: John Hubbard @ 2024-05-06 19:08 UTC (permalink / raw)
  To: Kees Cook
  Cc: Shuah Khan, Eric Biederman, Muhammad Usama Anjum, Mark Brown,
	linux-mm, Valentin Obst, linux-kselftest, LKML, llvm

On 5/6/24 10:09 AM, Kees Cook wrote:
> On Fri, May 03, 2024 at 07:23:01PM -0700, John Hubbard wrote:
>> clang doesn't deal well with "-pie -static": it warns that -pie is an
>> unused option here. Changing to "-fPIE -static" solves this problem for
>> clang, while keeping the gcc results identical.
>>
>> The problem is visible when building via:
>>
>>      make LLVM=1 -C tools/testing/selftests
>>
>> Again: gcc 13 produces identical binaries for all of these programs,
>> both before and after this commit (using "-pie"), and after (using
>> "-fPIE").
>>
>> Also, the runtime results are the same for both clang and gcc builds.
> 
> Thanks for this! It got solved differently here:
> https://lkml.kernel.org/r/20240416152831.3199999-1-usama.anjum@collabora.com
> 
> Does that work for you as well?
> 

Yes it does. Please drop my patch and let's use yours instead, thanks!

(As an aside, outside of the compiler sources themselves, it has
proven quite difficult to find any in-depth documentation of linking
options and behavior--now, and in the past.)

thanks,
-- 
John Hubbard
NVIDIA



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-06 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-04  2:23 [PATCH] selftests/exec: build with -fPIE instead of -pie, to make clang happy John Hubbard
2024-05-06 17:09 ` Kees Cook
2024-05-06 19:08   ` John Hubbard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox