Skip to contentSkip to conversation

tools/power/x86/intel-speed-select: fix build failure when using -Wl,--as-needed

PATCH In review Herton R. Krzesinski 4 participants 4 messages Apr 4, 2022 – Apr 5, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/power/x86/intel-speed-select: fix build failure when using -Wl,--as-needed

Build of intel-speed-select will fail if you run:

$ LDFLAGS="-Wl,--as-needed" /usr/bin/make V=1
...
gcc -O2 -Wall -g -D_GNU_SOURCE -Iinclude -I/usr/include/libnl3 -Wl,--as-needed -lnl-genl-3 -lnl-3 intel-speed-select-in.o -o intel-speed-select
/usr/bin/ld: intel-speed-select-in.o: in function `handle_event':
(...)/linux/tools/power/x86/intel-speed-select/hfi-events.c:189: undefined reference to `nlmsg_hdr'
...

In this case the problem is that order when linking matters when using the flag -Wl,--as-needed, symbols not used at that point are discarded. So since intel-speed-select-in.o comes after, at that point the libraries/symbols are already discarded and then missing/undefined references are reported.

To fix this, make sure we specify LDFLAGS after the object file.

---
 tools/power/x86/intel-speed-select/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/intel-speed-select/Makefile +1 -1
index 846f785e278d..7221f2f55e8b 100644
@@ -42,7 +42,7 @@ ISST_IN := $(OUTPUT)intel-speed-select-in.o
 $(ISST_IN): prepare FORCE
 	$(Q)$(MAKE) $(build)=intel-speed-select
 $(OUTPUT)intel-speed-select: $(ISST_IN)
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+	$(QUIET_LINK)$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
 
 clean:
 	rm -f $(ALL_PROGRAMS)
Signature · 1 line
2.35.1
#1 lore raw
Quoted 9 lines · Herton R. Krzesinski

Build of intel-speed-select will fail if you run:

$ LDFLAGS="-Wl,--as-needed" /usr/bin/make V=1
...
gcc -O2 -Wall -g -D_GNU_SOURCE -Iinclude -I/usr/include/libnl3 -Wl,--as-needed -lnl-genl-3 -lnl-3 intel-speed-select-in.o -o intel-speed-select
/usr/bin/ld: intel-speed-select-in.o: in function `handle_event':
(...)/linux/tools/power/x86/intel-speed-select/hfi-events.c:189: undefined reference to `nlmsg_hdr'
...

Srinivas, This is important as it blocks ARK (ie think of RHEL-next) kernel builds and blocks us from bringing this code into current versions of RHEL.

Just an FYI,

P.

Quoted 26 lines

In this case the problem is that order when linking matters when using the flag -Wl,--as-needed, symbols not used at that point are discarded. So since intel-speed-select-in.o comes after, at that point the libraries/symbols are already discarded and then missing/undefined references are reported.

To fix this, make sure we specify LDFLAGS after the object file.

---
  tools/power/x86/intel-speed-select/Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/intel-speed-select/Makefile +1 -1
index 846f785e278d..7221f2f55e8b 100644
@@ -42,7 +42,7 @@ ISST_IN := $(OUTPUT)intel-speed-select-in.o
  $(ISST_IN): prepare FORCE
  	$(Q)$(MAKE) $(build)=intel-speed-select
  $(OUTPUT)intel-speed-select: $(ISST_IN)
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+	$(QUIET_LINK)$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
 
  clean:
  	rm -f $(ALL_PROGRAMS)
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Herton R. Krzesinski
Quoted 3 lines · Herton R. Krzesinski

Build of intel-speed-select will fail if you run:

$ LDFLAGS="-Wl,--as-needed" /usr/bin/make V=1

We realized this for some OS recently have an internal patch. So agree with the change.

Quoted 15 lines

...
gcc -O2 -Wall -g -D_GNU_SOURCE -Iinclude -I/usr/include/libnl3 -Wl,-- as-needed -lnl-genl-3 -lnl-3 intel-speed-select-in.o -o intel-speed- select
/usr/bin/ld: intel-speed-select-in.o: in function `handle_event':
(...)/linux/tools/power/x86/intel-speed-select/hfi-events.c:189:
undefined reference to `nlmsg_hdr'
...

In this case the problem is that order when linking matters when using the flag -Wl,--as-needed, symbols not used at that point are discarded. So since intel-speed-select-in.o comes after, at that point the libraries/symbols are already discarded and then missing/undefined references are reported.

Quoted 3 lines

To fix this, make sure we specify LDFLAGS after the object file.

Quoted 18 lines

---
 tools/power/x86/intel-speed-select/Makefile | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/intel-speed-select/Makefile +0 -0
index 846f785e278d..7221f2f55e8b 100644
@@ -42,7 +42,7 @@ ISST_IN := $(OUTPUT)intel-speed-select-in.o

 $(ISST_IN): prepare FORCE
        $(Q)$(MAKE) $(build)=intel-speed-select $(OUTPUT)intel-speed-select: $(ISST_IN)
-       $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ +       $(QUIET_LINK)$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
 clean:
        rm -f $(ALL_PROGRAMS)

#3 lore raw
In reply to Herton R. Krzesinski

Hi All,

Quoted 15 lines · Herton R. Krzesinski

Build of intel-speed-select will fail if you run:

$ LDFLAGS="-Wl,--as-needed" /usr/bin/make V=1
...
gcc -O2 -Wall -g -D_GNU_SOURCE -Iinclude -I/usr/include/libnl3 -Wl,--as-needed -lnl-genl-3 -lnl-3 intel-speed-select-in.o -o intel-speed-select
/usr/bin/ld: intel-speed-select-in.o: in function `handle_event':
(...)/linux/tools/power/x86/intel-speed-select/hfi-events.c:189: undefined reference to `nlmsg_hdr'
...

In this case the problem is that order when linking matters when using the flag -Wl,--as-needed, symbols not used at that point are discarded. So since intel-speed-select-in.o comes after, at that point the libraries/symbols are already discarded and then missing/undefined references are reported.

Quoted 3 lines

To fix this, make sure we specify LDFLAGS after the object file.

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

I've also added this to my fixes branch and it will be included when I send the next fixes for 5.18 pull-req to Linus.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 17 lines
---
 tools/power/x86/intel-speed-select/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/intel-speed-select/Makefile +1 -1
index 846f785e278d..7221f2f55e8b 100644
@@ -42,7 +42,7 @@ ISST_IN := $(OUTPUT)intel-speed-select-in.o
 $(ISST_IN): prepare FORCE
 	$(Q)$(MAKE) $(build)=intel-speed-select
 $(OUTPUT)intel-speed-select: $(ISST_IN)
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+	$(QUIET_LINK)$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
 
 clean:
 	rm -f $(ALL_PROGRAMS)