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 · 10 comments · May be fixed by #1959
Open

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

vt-alt opened this issue Dec 28, 2023 · 10 comments · May be fixed by #1959

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.

@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.

@JangSoJin
Copy link
Contributor

Hi,
if this issue has not resolved yet, can i proceed it?

@namhyung
Copy link
Owner

Yep, please go ahead!

@deepseafishy
Copy link

Hi, I looked into this issue a couple of weeks back and now I have a small question regarding the checks of gelf.h.
I see that it might be best to work with a temporary binary to check if libelf-devel is installed and gelf.h is included.
I was just wondering if it is weird or not safe to let __have_libelf.c check for gelf.h with the binaries created during ./configure?
Or is it always safe to create a temporary binary during the run of have_libelf?

@namhyung
Copy link
Owner

namhyung commented Sep 1, 2024

The __have_libelf.c would create have_libelf binary during the check. And uftrace checks if it can see the binary in the check-deps directory. Why do you want another temporary binary?

@deepseafishy
Copy link

Maybe I wasn't clear; I thought the presence of GElf_Ehdr ehdr; in __have_libelf.c was to check if gelf.h was present after installing libelf-dev.
But since -Wall treats all warnings as an error, I thought that it would be best to read in the ELF header of an existing binary using something like gelf_getehdr() instead of having an unused variable to check for gelf.h.
So then I thought that maybe we could read in the header from one of the binaries created during ./configure, and I was just simply wondering if is a bad practice to have a binary created during ./configure to access another binary created during ./configure.

@namhyung
Copy link
Owner

namhyung commented Sep 2, 2024

Ok, I think you can put the code that uses gelf functions in the __have_libelf.c directly. It doesn't need to deal with real files as it only checks if it's compiled or not.

@JangSoJin
Copy link
Contributor

@namhyung Hello, I'm trying to solve the above issue, and I'd like to suggest the following :

Instead of __attribute__(unused), I putted the glef_checksum() function from gelf.h in __have_libelf.c.
FYI, for the first argument value of elf_begin, 'file_descriptor', I set it to '0', which is a dummy value, so please let me know if i need to modify it.

#include <gelf.h>
#include <libelf.h>

int main(void)
{
      Elf *elf;

      elf_version(EV_CURRENT);

      /* check that the gelf function */
      elf = elf_begin(0, ELF_C_READ, 0);
      gelf_checksum(elf);
      elf_end(elf);

      return 0;
}

@namhyung
Copy link
Owner

namhyung commented Sep 2, 2024

Looks good, the only nitpick is the third argument of elf_begin is a pointer, so you'd better pass NULL instead of 0.

@JangSoJin JangSoJin linked a pull request Sep 2, 2024 that will close this issue
JangSoJin added a commit to JangSoJin/uftrace that referenced this issue Sep 3, 2024
Even though 'libelf-devel' is installed,
'libelf' is displayed as [OFF] rather than [ON] when running ./configure.

Fixed : namhyung#1869
(issue : gcc -Wall -Werror: libelf: [ OFF ] even when libelf-devel is installed)

Signed-off-by: Sojin Jang <[email protected]>
JangSoJin added a commit to JangSoJin/uftrace that referenced this issue Sep 3, 2024
Even though 'libelf-devel' is installed,
'libelf' is displayed as [OFF] rather than [ON] when running ./configure.

Fixed : namhyung#1869
(issue : gcc -Wall -Werror: libelf: [ OFF ] even when libelf-devel is installed)

Signed-off-by: Sojin Jang <[email protected]>
JangSoJin added a commit to JangSoJin/uftrace that referenced this issue Sep 3, 2024
Even though 'libelf-devel' is installed,
'libelf' is displayed as [OFF] rather than [ON] when running ./configure.

Fixed : namhyung#1869
(issue : gcc -Wall -Werror: libelf: [ OFF ] even when libelf-devel is installed)

Signed-off-by: Sojin Jang <[email protected]>
JangSoJin added a commit to JangSoJin/uftrace that referenced this issue Sep 3, 2024
Even though 'libelf-devel' is installed,
'libelf' is displayed as [OFF] rather than [ON]
when running ./configure.

Fixed : namhyung#1869

Signed-off-by: SoJin Jang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants