From: Nick Alcock Date: Thu, 19 May 2016 20:45:56 +0000 (+0100) Subject: dtrace: support SDT in single-file modules X-Git-Tag: v4.1.12-92~155^2~5 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=daf016df43a40608ca00906c9c42bcbdb48712e3;p=users%2Fjedix%2Flinux-maple.git dtrace: support SDT in single-file modules A limitation of long standing in the SDT machinery is that it didn't support modules that were implemented entirely in one file. This is because the SDT stubs generation machinery (which emits zero-byte assembler stubs for all DTrace probe points) was implemented at the point at which multi-file modules are linked into a single file prior to modpost. Since single-file modules *have* no such stage, they never got their stubs, and probes never fired. This becomes essential to fix so that perf_events probes will work, because some of those are in single-file modules. We fix it by tearing out the sdtstub code from its prior home in Makefile.build, and moving it into the late modpost stage, at the same point at which sdtinfo files are generated. We use the same prerequites trick as is used for CTF files to link the sdtstub files into the resulting modules; because this all happens at the very last possible moment, it shares the same code path for single- and multifile modules, and is a good bit simpler to boot (no need to manipulate the link process or transform filenames intricately during stub generation). There is one additional wrinkle: because the dtrace probes are now always undefined until the last minute, we must adjust modpost to disregard all undefined symbols that start "__dtrace_probe_". Orabug: 23316392 Signed-off-by: Nick Alcock Acked-by: Kris Van Hees --- diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 63645acf5d7ab..01df30af4d4a5 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -380,38 +380,9 @@ $($(subst $(obj)/,,$(@:.o=-y)))), $^) quiet_cmd_link_multi-y = LD $@ cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) -ifdef CONFIG_DTRACE - -# We need secondary expansion for the %.sdtstub.S creation rule -.SECONDEXPANSION: - -sdtgen = $(srctree)/scripts/dtrace_sdt.sh - -quiet_cmd_sdtstub = SDTSTB $@ - cmd_sdtstub = $(sdtgen) sdtstub $@ \ - $(filter $(addprefix $(obj)/, \ - $($(subst $(obj)/,,$(@:.sdtstub.S=-objs))) \ - $($(subst $(obj)/,,$(@:.sdtstub.S=-y)))), \ - $(subst |,,$(multi-objs-m))) - -$(multi-used-m:.o=.sdtstub.S) : %.sdtstub.S: $(multi-objs-m) - $(call if_changed,sdtstub) - -$(multi-used-m:.o=.sdtstub.o) : %.sdtstub.o: %.sdtstub.S - $(call if_changed,as_o_S) - -$(multi-used-m) : %.o: %.sdtstub.o - -quiet_cmd_link_multi-m = LD [M] $@ -cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $*.sdtstub.o $(cmd_secanalysis) - -else - quiet_cmd_link_multi-m = LD [M] $@ cmd_link_multi-m = $(cmd_link_multi-y) -endif - $(multi-used-y): FORCE $(call if_changed,link_multi-y) $(call multi_depend, $(multi-used-y), .o, -objs -y) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 9039cd5fb4d0d..2ad9dd919661b 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -105,7 +105,8 @@ vmlinux.o: FORCE $(symverfile): __modpost ; $(modules:.ko=.mod.c): __modpost ; -# Step 5), compile all *.mod.c files (includes the generation of SDT data) +# Step 5), compile all *.mod.c files (includes the generation of SDT data +# and SDT stubs) # modname is set to make c_flags define KBUILD_MODNAME modname = $(notdir $(@:.mod.o=)) @@ -114,6 +115,9 @@ quiet_cmd_cc_o_c = CC $@ cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \ -I$(dir $@) -c -o $@ $< +quiet_cmd_as_o_S = AS $@ + cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< + ifdef CONFIG_DTRACE sdtgen = $(srctree)/scripts/dtrace_sdt.sh @@ -121,16 +125,30 @@ sdtgen = $(srctree)/scripts/dtrace_sdt.sh quiet_cmd_sdtinfo = SDTINF $@ cmd_sdtinfo = $(sdtgen) sdtinfo $@ $< kmod +quiet_cmd_sdtstub = SDTSTB $@ + cmd_sdtstub = $(sdtgen) sdtstub $@ $< + $(modules:.ko=.sdtinfo.c): %.sdtinfo.c: %.o $(call cmd,sdtinfo) +$(modules:.ko=.sdtstub.S) : %.sdtstub.S: %.o + $(call cmd,sdtstub) + $(modules:.ko=.mod.o): %.mod.o: %.mod.c %.sdtinfo.c FORCE $(call if_changed_dep,cc_o_c) + +$(modules:.ko=.sdtstub.o): %.sdtstub.o: %.sdtstub.S + $(call if_changed,as_o_S) + +module-sdt-modular-prereq = %.sdtstub.o + else $(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE $(call if_changed_dep,cc_o_c) +module-sdt-modular-prereq = + endif targets += $(modules:.ko=.mod.o) @@ -264,7 +282,7 @@ quiet_cmd_ld_ko_o = LD [M] $@ $(patsubst $(ctf-dir)/%,,$(filter-out FORCE,$^)) && \ $(OBJCOPY) $(module-ctf-flags) $@.tmp $@ && rm -f $@.tmp -$(modules): %.ko : %.o %.mod.o $(module-ctfs-modular-prereq) FORCE +$(modules): %.ko : %.o %.mod.o $(module-sdt-modular-prereq) $(module-ctfs-modular-prereq) FORCE $(call cmd_touch_ctf) $(call if_changed,ld_ko_o) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 148af0d92eae6..8ac053304ad3d 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2158,7 +2158,8 @@ static int add_versions(struct buffer *b, struct module *mod) for (s = mod->unres; s; s = s->next) { exp = find_symbol(s->name); if (!exp || exp->module == mod) { - if (have_vmlinux && !s->weak) { + if (have_vmlinux && !s->weak && + !strstarts(s->name, "__dtrace_probe_")) { if (warn_unresolved) { warn("\"%s\" [%s.ko] undefined!\n", s->name, mod->name);