Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc -Wall -Werror: libelf: [ OFF ] even when libelf-devel is installed #1869

Open
vt-alt opened this issue Dec 28, 2023 · 3 comments
Open

gcc -Wall -Werror: libelf: [ OFF ] even when libelf-devel is installed #1869

vt-alt opened this issue Dec 28, 2023 · 3 comments

Comments

@vt-alt
Copy link

vt-alt commented Dec 28, 2023

JFYI:
In ALT we compiling with CFLAGS='-pipe -frecord-gcc-switches -Wall -g -O2 ' by default (but no -Werror). With this libelf tests always negative even when libelf-devel is installed.

With this patch

diff --git a/check-deps/Makefile b/check-deps/Makefile
index 22e33f34..7887b436 100644
--- a/check-deps/Makefile
+++ b/check-deps/Makefile
@@ -58,7 +58,7 @@ LDFLAGS_have_libtraceevent = $(shell pkg-config --libs  libtraceevent 2> /dev/nu
 check-build: $(CHECK_LIST)

 $(CHECK_LIST): %: __%.c $(CHKDIR)/check-tstamp
-        @$(CC) $(CHECK_CFLAGS) -o $(CHKDIR)/$@  $< $(CHECK_LDFLAGS) > /dev/null 2>&1
+        set -x; $(CC) $(CHECK_CFLAGS) -o $(CHKDIR)/$@  $< $(CHECK_LDFLAGS)

 $(CHKDIR)/check-tstamp: PHONY
         @mkdir -p $(dir $@)

we see

+ gcc -pipe -frecord-gcc-switches -Wall -g -O2 -Werror -o /usr/src/RPM/BUILD/uftrace-0.14/check-deps/have_libelf __have_libelf.c -lelf
__have_libelf.c: In function 'main':
__have_libelf.c:6:19: error: unused variable 'ehdr' [-Werror=unused-variable]
    6 |         GElf_Ehdr ehdr;
      |                   ^~~~
cc1: all warnings being treated as errors

In gcc 13.2.1 -Wunused-variable is included in -Wall:

$ gcc --help=warning -Q | grep unused-var
  -Wunused-variable                     [disabled]
$ gcc -Wall --help=warning -Q | grep unused-var
  -Wunused-variable                     [enabled]

I easily (except the time to find this) workaround this by adding -Wno-error=unused-variable to CFLAGS.

@namhyung
Copy link
Owner

Ok, I think we can add "unused" attribute to those variables to prevent compiler warnings.

@marc-delgado-ferreres
Copy link

A solution you have proposed is to add the "-Wno-error=unused-variable" flag to your CFLAGS to prevent the compiler from treating warnings as errors. However, you could also consider another solution, which is to add the "unused" attribute to the variables causing the warnings. This can be done as follows in your code:

attribute((unused)) GElf_Ehdr ehdr;

By adding this attribute to the variables generating warnings, you're telling the compiler to ignore them in terms of warnings about unused variables

@namhyung
Copy link
Owner

namhyung commented Feb 8, 2024

Ok, I think we should save the output of compiler during the dependency check. And for the libelf case specifically, it can simply remove the ehdr variable as it's not needed by the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants