public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ulf Hermann <ulf.hermann@digia.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH] perf tool: Allow mixed static/dynamic linking
Date: Thu, 22 May 2014 17:10:56 +0200	[thread overview]
Message-ID: <537E1380.7040604@digia.com> (raw)

Listen to a STATIC_LDFLAGS environment variable which will be
appended to a -Wl,-Bstatic in each link step. Remove its contents
from the regular link flags to avoid linking conflicts. Like that
some of the libraries can be statically linked while others are
linked dynamically.

Signed-off-by: Ulf Hermann <ulf.hermann@digia.com>

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 895edd3..b1c1ff4 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -29,7 +29,10 @@ include config/utilities.mak
  #
  # Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72.
  #
-# Define LDFLAGS=-static to build a static binary.
+# Define LDFLAGS=-static to build a completely static binary.
+#
+# Define STATIC_LDFLAGS to specify link flags that should follow a -Wl,-Bstatic.
+# Those flags will be removed from the automatically determined, dynamic flags.
  #
  # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds.
  #
@@ -558,7 +561,9 @@ ifdef ASCIIDOC8
    export ASCIIDOC8
  endif
  
-LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
+LDFLAGS := $(filter-out $(STATIC_LDFLAGS), $(LDFLAGS))
+LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive\
+	-Wl,--start-group $(filter-out $(STATIC_LDFLAGS) $(LDFLAGS), $(EXTLIBS)) -Wl,--end-group
  
  export INSTALL SHELL_PATH
  
@@ -582,8 +587,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
  		$(CFLAGS) -c $(filter %.c,$^) -o $@
  
  $(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(OUTPUT)perf.o \
-               $(BUILTIN_OBJS) $(LIBS) -o $@
+	$(QUIET_LINK)$(CC) $(CFLAGS) $(OUTPUT)perf.o $(BUILTIN_OBJS) \
+		$(LIBS) -Wl,-Bstatic $(STATIC_LDFLAGS) -Wl,-Bdynamic $(LDFLAGS) -o $@
  
  $(GTK_OBJS): $(OUTPUT)%.o: %.c $(LIB_H)
  	$(QUIET_CC)$(CC) -o $@ -c -fPIC $(CFLAGS) $(GTK_CFLAGS) $<
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile
index 2da103c..62f6060 100644
--- a/tools/perf/config/feature-checks/Makefile
+++ b/tools/perf/config/feature-checks/Makefile
@@ -34,60 +34,72 @@ PKG_CONFIG := $(CROSS_COMPILE)pkg-config
  
  all: $(FILES)
  
-BUILD = $(CC) $(CFLAGS) -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS)
+define build
+	$(CC) $(CFLAGS) -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) -Wl,-Bstatic $(STATIC_LDFLAGS)\
+		-Wl,-Bdynamic $(filter-out $(STATIC_LDFLAGS), $(LDFLAGS) $(1))
+endef
+
+define build-spefic-source
+	$(CC) $(CFLAGS) -o $(OUTPUT)$@ $(1) -Wl,-Bstatic $(STATIC_LDFLAGS)\
+		-Wl,-Bdynamic $(filter-out $(STATIC_LDFLAGS), $(LDFLAGS) $(2))
+endef
+
  
  ###############################
  
  test-all.bin:
-	$(BUILD) -Werror -fstack-protector-all -O2 -Werror -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl
+	$(call build, -Werror -fstack-protector-all -O2 -Werror -D_FORTIFY_SOURCE=2 -I/usr/include/slang\
+		-ldw -lelf -lnuma -laudit -lslang -lbfd -ldl\
+		$(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)\
+		$(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"')
  
  test-hello.bin:
-	$(BUILD)
+	$(call build)
  
  test-stackprotector-all.bin:
-	$(BUILD) -Werror -fstack-protector-all
+	$(call build, -Werror -fstack-protector-all)
  
  test-fortify-source.bin:
-	$(BUILD) -O2 -Werror -D_FORTIFY_SOURCE=2
+	$(call build, -O2 -Werror -D_FORTIFY_SOURCE=2)
  
  test-bionic.bin:
-	$(BUILD)
+	$(call build)
  
  test-libelf.bin:
-	$(BUILD) -lelf
+	$(call build, -lelf)
  
  test-glibc.bin:
-	$(BUILD)
+	$(call build)
  
  test-dwarf.bin:
-	$(BUILD) -ldw
+	$(call build, -ldw)
  
  test-libelf-mmap.bin:
-	$(BUILD) -lelf
+	$(call build, -lelf)
  
  test-libelf-getphdrnum.bin:
-	$(BUILD) -lelf
+	$(call build, -lelf)
  
  test-libnuma.bin:
-	$(BUILD) -lnuma
+	$(call build, -lnuma)
  
  test-libunwind.bin:
-	$(BUILD) -lelf
+	$(call build, -lelf)
  
  test-libunwind-debug-frame.bin:
-	$(BUILD) -lelf
+	$(call build, -lelf)
  
  test-libaudit.bin:
-	$(BUILD) -laudit
+	$(call build, -laudit)
  
  test-libslang.bin:
-	$(BUILD) -I/usr/include/slang -lslang
+	$(call build, -I/usr/include/slang -lslang)
  
  test-gtk2.bin:
-	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
+	$(call build, $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null))
  
  test-gtk2-infobar.bin:
-	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
+	$(call build, $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null))
  
  grep-libs  = $(filter -l%,$(1))
  strip-libs = $(filter-out -l%,$(1))
@@ -99,7 +111,7 @@ PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  
  test-libperl.bin:
-	$(BUILD) $(FLAGS_PERL_EMBED)
+	$(call build, $(FLAGS_PERL_EMBED))
  
  override PYTHON := python
  override PYTHON_CONFIG := python-config
@@ -116,34 +128,34 @@ PYTHON_EMBED_CCOPTS = $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
  FLAGS_PYTHON_EMBED = $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  
  test-libpython.bin:
-	$(BUILD) $(FLAGS_PYTHON_EMBED)
+	$(call build, $(FLAGS_PYTHON_EMBED))
  
  test-libpython-version.bin:
-	$(BUILD) $(FLAGS_PYTHON_EMBED)
+	$(call build, $(FLAGS_PYTHON_EMBED))
  
  test-libbfd.bin:
-	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
+	$(call build, -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl)
  
  test-liberty.bin:
-	$(CC) -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' -lbfd -ldl -liberty
+	$(call build-specific-source, test-libbfd.c, -DPACKAGE='"perf"' -lbfd -ldl -liberty)
  
  test-liberty-z.bin:
-	$(CC) -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' -lbfd -ldl -liberty -lz
+	$(call build-specific-source, test-libbfd.c, -DPACKAGE='"perf"' -lbfd -ldl -liberty -lz)
  
  test-cplus-demangle.bin:
-	$(BUILD) -liberty
+	$(call build, -liberty)
  
  test-on-exit.bin:
-	$(BUILD)
+	$(call build)
  
  test-backtrace.bin:
-	$(BUILD)
+	$(call build)
  
  test-timerfd.bin:
-	$(BUILD)
+	$(call build)
  
  test-libdw-dwarf-unwind.bin:
-	$(BUILD)
+	$(call build)
  
  -include *.d
  

                 reply	other threads:[~2014-05-22 15:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=537E1380.7040604@digia.com \
    --to=ulf.hermann@digia.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox