sched_ext: Clean up -rdynamic and LDFLAGS in Makefiles
Subsystems (2)
cover sched_ext: Clean up -rdynamic and LDFLAGS in Makefiles
Building the demo schedulers and selftests with CC=clang-N fails under -Werror because CFLAGS passes the link-time flag -rdynamic to compile steps ($(CC) -c):
$ make CC=clang-21
clang-21: error: argument unused during compilation: '-rdynamic'
[-Werror,-Wunused-command-line-argument]Patch 1: Drop the inert -rdynamic from tools/sched_ext. Binaries remain byte-identical before and after.
Patch 2: Move -rdynamic to LDFLAGS and append with '+=' in selftests.
Thanks,
Cheng-Yang
---
Cheng-Yang Chou (2):
tools/sched_ext: Drop the no-op -rdynamic from CFLAGS selftests/sched_ext: Move -rdynamic to LDFLAGS and append to it
tools/sched_ext/Makefile | 2 +- tools/testing/selftests/sched_ext/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 tools/sched_ext: Drop the no-op -rdynamic from CFLAGS
Because CFLAGS only applies to compilation ($(CC) -c), the link-time flag -rdynamic is inert during the build. Schedulers do not rely on exported dynamic symbols, and binaries remain byte-identical without it.
Under -Werror, Clang treats this unused argument as a build error:
$ make CC=clang-21 clang-21: error: argument unused during compilation: '-rdynamic' [-Werror,-Wunused-command-line-argument]
Drop -rdynamic from CFLAGS to ensure clean builds across Clang versions.
--- tools/sched_ext/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/sched_ext/Makefile +1 -1
@@ -89,7 +89,7 @@ ifneq ($(wildcard $(GENHDR)),) GENFLAGS := -DHAVE_GENHDR endif -CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \ +CFLAGS += -g -O2 -pthread -Wall -Werror $(GENFLAGS) \ -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include
Signature · 1 line
2.43.0
PATCH 2/2 selftests/sched_ext: Move -rdynamic to LDFLAGS and append to it
CFLAGS passes the link-time flag -rdynamic to compile steps ($(CC) -c), where it is unused. Under -Werror, Clang fails the build:
$ make CC=clang-21
clang-21: error: argument unused during compilation: '-rdynamic'
[-Werror,-Wunused-command-line-argument]Unlike the demo schedulers, the selftest runner requires -rdynamic at link time to populate .dynsym for testcases. Additionally, LDFLAGS uses '=' rather than '+=', silently discarding USERLDFLAGS from lib.mk.
Move -rdynamic from CFLAGS to LDFLAGS and append with '+='. This fixes builds with CC=clang-N while preserving symbol export and USERLDFLAGS.
--- tools/testing/selftests/sched_ext/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/sched_ext/Makefile +2 -2
@@ -53,7 +53,7 @@ ifneq ($(wildcard $(GENHDR)),) GENFLAGS := -DHAVE_GENHDR endif -CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \ +CFLAGS += -g -O2 -pthread -Wall -Werror $(GENFLAGS) \ -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR)
@@ -62,7 +62,7 @@ ifneq ($(LLVM),) CFLAGS += -Wno-unused-command-line-argument endif -LDFLAGS = -lelf -lz -lpthread -lzstd +LDFLAGS += -rdynamic -lelf -lz -lpthread -lzstd IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \ grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
Signature · 1 line
2.43.0
Tejun Heo
reviewerRe: [PATCH 2/2] selftests/sched_ext: Move -rdynamic to LDFLAGS and append to it
Hello,
Quoted 3 lines · Cheng-Yang Chou
Unlike the demo schedulers, the selftest runner requires -rdynamic at link time to populate .dynsym for testcases. Additionally, LDFLAGS uses '=' rather than '+=', silently discarding USERLDFLAGS from lib.mk.
The runner doesn't need -rdynamic. Testcases register through constructors calling scx_test_register() and nothing in the selftests, tools/sched_ext or libbpf looks up symbols dynamically or prints backtraces. The flag was copied from the BPF selftests where the test_progs crash handler needs it for backtrace symbolization. Please drop -rdynamic here too, as in the first patch. The '=' to '+=' change is good, keep that.
Thanks.
--
tejun
Re: [PATCH 2/2] selftests/sched_ext: Move -rdynamic to LDFLAGS and append to it
Hi Tejun,
Quoted 7 lines · Tejun Heo
Hello,
Quoted 3 lines · Cheng-Yang Chou
Unlike the demo schedulers, the selftest runner requires -rdynamic at link time to populate .dynsym for testcases. Additionally, LDFLAGS uses '=' rather than '+=', silently discarding USERLDFLAGS from lib.mk.
Quoted 6 lines
The runner doesn't need -rdynamic. Testcases register through constructors calling
scx_test_register()and nothing in the selftests,tools/sched_extor libbpf looks up symbols dynamically or prints backtraces. The flag was copied from the BPF selftests where thetest_progscrash handler needs it for backtrace symbolization. Please drop -rdynamic here too, as in the first patch. The '=' to '+=' change is good, keep that.
Confirmed here, dropping it takes the runner's .dynsym from 572 to 172 entries, and all testcases still register and run, so nothing was relying on the exported symbols.
Will send v2 patch soon, thanks!
Quoted 5 lines
Thanks.
--
tejun
Signature · 2 lines
Cheers, Cheng-Yang
Re: [PATCH 1/2] tools/sched_ext: Drop the no-op -rdynamic from CFLAGS
In reply to Cheng-Yang ChouHello,
Quoted 3 lines · Cheng-Yang Chou
Because CFLAGS only applies to compilation ($(CC) -c), the link-time flag -rdynamic is inert during the build. Schedulers do not rely on exported dynamic symbols, and binaries remain byte-identical without it.
Applied to sched_ext/for-7.4.
Thanks.
--
tejun