diff mbox series

[1/6] tools/rtla: Fix Makefile compiler options for clang

Message ID 567ac1b94effc228ce9a0225b9df7232a9b35b55.1707217097.git.bristot@kernel.org (mailing list archive)
State Mainlined
Headers show
Series tools: Fix rtla and rv problems (found) with clang | expand

Commit Message

Daniel Bristot de Oliveira Feb. 6, 2024, 11:05 a.m. UTC
The following errors are showing up when compiling rtla with clang:

 $ make HOSTCC=clang CC=clang LLVM_IAS=1
 [...]

  clang -O -g -DVERSION=\"6.8.0-rc1\" -flto=auto -ffat-lto-objects
	-fexceptions -fstack-protector-strong
	-fasynchronous-unwind-tables -fstack-clash-protection  -Wall
	-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
	-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
	$(pkg-config --cflags libtracefs)    -c -o src/utils.o src/utils.c

  clang: warning: optimization flag '-ffat-lto-objects' is not supported [-Wignored-optimization-argument]
  warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option]
  1 warning generated.

  clang -o rtla -ggdb  src/osnoise.o src/osnoise_hist.o src/osnoise_top.o
  src/rtla.o src/timerlat_aa.o src/timerlat.o src/timerlat_hist.o
  src/timerlat_top.o src/timerlat_u.o src/trace.o src/utils.o $(pkg-config --libs libtracefs)

  src/osnoise.o: file not recognized: file format not recognized
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [Makefile:110: rtla] Error 1

Solve these issues by:
  - removing -ffat-lto-objects and -Wno-maybe-uninitialized if using clang
  - informing the linker about -flto=auto

Cc: stable@vger.kernel.org
Fixes: 1a7b22ab15eb ("tools/rtla: Build with EXTRA_{C,LD}FLAGS")
Suggested-by: Donald Zickus <dzickus@redhat.com>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
---
 tools/tracing/rtla/Makefile | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Nathan Chancellor Feb. 6, 2024, 3:48 p.m. UTC | #1
On Tue, Feb 06, 2024 at 12:05:29PM +0100, Daniel Bristot de Oliveira wrote:
> The following errors are showing up when compiling rtla with clang:
> 
>  $ make HOSTCC=clang CC=clang LLVM_IAS=1
>  [...]
> 
>   clang -O -g -DVERSION=\"6.8.0-rc1\" -flto=auto -ffat-lto-objects
> 	-fexceptions -fstack-protector-strong
> 	-fasynchronous-unwind-tables -fstack-clash-protection  -Wall
> 	-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
> 	-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
> 	$(pkg-config --cflags libtracefs)    -c -o src/utils.o src/utils.c
> 
>   clang: warning: optimization flag '-ffat-lto-objects' is not supported [-Wignored-optimization-argument]

For what it's worth, this flag is supported in clang 17.0.0 and newer:

https://github.com/llvm/llvm-project/commit/610fc5cbcc8b68879c562f6458608afe2473ab7f

But if it is not critical, just dropping the flag like you have done
here rather than conditionally supporting it is probably easier.

>   warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option]
>   1 warning generated.
> 
>   clang -o rtla -ggdb  src/osnoise.o src/osnoise_hist.o src/osnoise_top.o
>   src/rtla.o src/timerlat_aa.o src/timerlat.o src/timerlat_hist.o
>   src/timerlat_top.o src/timerlat_u.o src/trace.o src/utils.o $(pkg-config --libs libtracefs)
> 
>   src/osnoise.o: file not recognized: file format not recognized
>   clang: error: linker command failed with exit code 1 (use -v to see invocation)
>   make: *** [Makefile:110: rtla] Error 1
> 
> Solve these issues by:
>   - removing -ffat-lto-objects and -Wno-maybe-uninitialized if using clang
>   - informing the linker about -flto=auto
> 
> Cc: stable@vger.kernel.org
> Fixes: 1a7b22ab15eb ("tools/rtla: Build with EXTRA_{C,LD}FLAGS")
> Suggested-by: Donald Zickus <dzickus@redhat.com>
> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
> ---
>  tools/tracing/rtla/Makefile | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
> index 2456a399eb9a..afd18c678ff5 100644
> --- a/tools/tracing/rtla/Makefile
> +++ b/tools/tracing/rtla/Makefile
> @@ -28,10 +28,15 @@ FOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
>  		-fasynchronous-unwind-tables -fstack-clash-protection
>  WOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
>  
> +ifeq ($(CC),clang)
> +  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
> +  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
> +endif
> +
>  TRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
>  
>  CFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
> -LDFLAGS	:=	-ggdb $(EXTRA_LDFLAGS)
> +LDFLAGS	:=	-flto=auto -ggdb $(EXTRA_LDFLAGS)
>  LIBS	:=	$$($(PKG_CONFIG) --libs libtracefs)
>  
>  SRC	:=	$(wildcard src/*.c)
> -- 
> 2.43.0
>
Daniel Bristot de Oliveira Feb. 8, 2024, 10:30 a.m. UTC | #2
On 2/6/24 16:48, Nathan Chancellor wrote:
> On Tue, Feb 06, 2024 at 12:05:29PM +0100, Daniel Bristot de Oliveira wrote:
>> The following errors are showing up when compiling rtla with clang:
>>
>>  $ make HOSTCC=clang CC=clang LLVM_IAS=1
>>  [...]
>>
>>   clang -O -g -DVERSION=\"6.8.0-rc1\" -flto=auto -ffat-lto-objects
>> 	-fexceptions -fstack-protector-strong
>> 	-fasynchronous-unwind-tables -fstack-clash-protection  -Wall
>> 	-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
>> 	-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
>> 	$(pkg-config --cflags libtracefs)    -c -o src/utils.o src/utils.c
>>
>>   clang: warning: optimization flag '-ffat-lto-objects' is not supported [-Wignored-optimization-argument]
> 
> For what it's worth, this flag is supported in clang 17.0.0 and newer:
> 
> https://github.com/llvm/llvm-project/commit/610fc5cbcc8b68879c562f6458608afe2473ab7f

Good! still, I am getting this error on fedora, with this clang version:

bristot@x1:~/src/git/linux/tools/tracing/rtla$ clang --version
clang version 17.0.6 (Fedora 17.0.6-1.fc39)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

:-(

> But if it is not critical, just dropping the flag like you have done
> here rather than conditionally supporting it is probably easier.

Yeah, I will drop it for now, and keep monitoring.

Thanks Natan!
-- Daniel
diff mbox series

Patch

diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index 2456a399eb9a..afd18c678ff5 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -28,10 +28,15 @@  FOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
 		-fasynchronous-unwind-tables -fstack-clash-protection
 WOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
 
+ifeq ($(CC),clang)
+  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
+  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+endif
+
 TRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
 
 CFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
-LDFLAGS	:=	-ggdb $(EXTRA_LDFLAGS)
+LDFLAGS	:=	-flto=auto -ggdb $(EXTRA_LDFLAGS)
 LIBS	:=	$$($(PKG_CONFIG) --libs libtracefs)
 
 SRC	:=	$(wildcard src/*.c)