Skip to content

Commit

Permalink
[NaCl SDK] fix shared library link rule in example build system.
Browse files Browse the repository at this point in the history
The rules for building shared libraries are now much
more similar to those for building executables. In
particular we honor the libraries paths and linker flags
for the project.

This discrepancy was causing the libraries to be linked
without -pthread, which was causing a failure under the
recent binutils update in the NaCl toolchain.

R=binji@chromium.org, mcgrathr@chromium.org

Review URL: https://codereview.chromium.org/84073002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237105 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sbc@chromium.org committed Nov 25, 2013
1 parent 880bbd7 commit 7d883a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
9 changes: 7 additions & 2 deletions native_client_sdk/src/resources/Makefile.library.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ EXTRA_INC_PATHS={{' '.join(target['INCLUDES'])}}
include $(NACL_SDK_ROOT)/tools/common.mk

TARGET = {{target['NAME']}}
[[ExpandDict('DEPS', targets[0].get('DEPS', []))]]
[[ExpandDict('LIBS', targets[0].get('LIBS', []), pre_list=['$(DEPS)'])]]
[[flags = target.get('CFLAGS', [])]]
[[flags.extend(target.get('CXXFLAGS', []))]]
[[ExpandDict('CFLAGS', flags)]]
Expand All @@ -53,13 +55,16 @@ SOURCES = \
all: install

# Build rules generated by macros from common.mk:
#

[[if targets[0].get('DEPS'):]]
$(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
[[]]
$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
$(eval $(call LIB_RULE,$(TARGET),$(SOURCES)))

[[if target['TYPE'] != 'static-lib':]]
ifeq ($(TOOLCHAIN),glibc)
$(eval $(call SO_RULE,$(TARGET),$(SOURCES)))
$(eval $(call SO_RULE,$(TARGET),$(SOURCES),$(LIBS),$(DEPS)))
endif
[[]]
{{post}}
41 changes: 23 additions & 18 deletions native_client_sdk/src/tools/nacl_gcc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
# http://www.gnu.org/software/make/manual/make.html
#


#
# Default library paths
#
LD_X86_32 := -L$(NACL_SDK_ROOT)/lib/$(TOOLCHAIN)_x86_32/$(CONFIG)
LD_X86_64 := -L$(NACL_SDK_ROOT)/lib/$(TOOLCHAIN)_x86_64/$(CONFIG)
LD_ARM := -L$(NACL_SDK_ROOT)/lib/$(TOOLCHAIN)_arm/$(CONFIG)


#
# Macros for TOOLS
#
# We always link with the C++ compiler but include -Wl,-as-needed flag
# in LD_FLAGS so the linker should drop libc++ unless it's actually needed.
# in LDFLAGS so the linker should drop libc++ unless it's actually needed.
#
X86_TC_BIN ?= $(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/bin
ARM_TC_BIN ?= $(TC_PATH)/$(OSNAME)_arm_$(TOOLCHAIN)/bin
Expand Down Expand Up @@ -61,6 +52,8 @@ X86_32_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_32.map
X86_64_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_64.map
ARM_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_arm.map

LDFLAGS_SHARED = -shared

#
# Compile Macro
#
Expand Down Expand Up @@ -178,44 +171,56 @@ GLIBC_REMAP :=
# $2 = List of Sources
# $3 = List of LIBS
# $4 = List of DEPS
# $5 = 1 => Don't add to NMF.
# $5 = Library Paths
# $6 = 1 => Don't add to NMF.
#
define SO_RULE
define SO_LINKER_RULE
ifneq (,$(findstring x86_32,$(ARCHES)))
all: $(OUTDIR)/lib$(1)_x86_32.so
$(OUTDIR)/lib$(1)_x86_32.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32_pic)) $(4)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter-out $(4),$$^) -shared -m32 $(LD_X86_32) $$(LD_FLAGS) $(foreach lib,$(3),-l$(lib)))
$(OUTDIR)/lib$(1)_x86_32.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -m32 $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib)))
$(call LOG,VALIDATE,$$@,$(NCVAL) $$@)

$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
$(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so: $(OUTDIR)/lib$(1)_x86_32.so
$(MKDIR) -p $$(dir $$@)
$(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
ifneq ($(5),1)
ifneq ($(6),1)
GLIBC_SO_LIST += $(OUTDIR)/lib$(1)_x86_32.so
GLIBC_REMAP += -n lib$(1)_x86_32.so,lib$(1).so
endif
endif

ifneq (,$(findstring x86_64,$(ARCHES)))
all: $(OUTDIR)/lib$(1)_x86_64.so
$(OUTDIR)/lib$(1)_x86_64.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64_pic)) $(4)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter-out $(4),$$^) -shared -m64 $(LD_X86_64) $$(LD_FLAGS) $(foreach lib,$(3),-l$(lib)))
$(OUTDIR)/lib$(1)_x86_64.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -m64 $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib)))
$(call LOG,VALIDATE,$$@,$(NCVAL) $$@)

$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
$(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so: $(OUTDIR)/lib$(1)_x86_64.so
$(MKDIR) -p $$(dir $$@)
$(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
ifneq ($(5),1)
ifneq ($(6),1)
GLIBC_SO_LIST += $(OUTDIR)/lib$(1)_x86_64.so
GLIBC_REMAP += -n lib$(1)_x86_64.so,lib$(1).so
endif
endif
endef

#
# $1 = Target Name
# $2 = List of Sources
# $3 = List of LIBS
# $4 = List of DEPS
# $5 = 1 => Don't add to NMF.
#
define SO_RULE
$(call SO_LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
endef

#
# LIB Macro
#
Expand Down

0 comments on commit 7d883a8

Please sign in to comment.