[Mesa-dev] [PATCH] gallium/targets: use c++ compiler for linking

Marcin Slusarz marcin.slusarz at gmail.com
Sun Oct 16 09:47:54 PDT 2011


On Sun, Oct 16, 2011 at 04:15:14PM +0200, Michel Dänzer wrote:
> On Son, 2011-10-16 at 14:54 +0200, Marcin Slusarz wrote: 
> > On Sun, Oct 16, 2011 at 02:03:16PM +0200, Marcin Slusarz wrote:
> > > On Fri, Oct 14, 2011 at 08:22:35AM +0200, Michel Dänzer wrote:
> > > > On Don, 2011-10-13 at 15:11 -0500, Patrick Baggett wrote:
> > > > > Well, trivial answer is that Win32 uses some C/C++ runtime provided by
> > > > > Microsoft, usually something like MSVCR90.DLL (v9.0) etc. Solaris uses
> > > > > libC.so, for example. As far as I know, only systems where the GNU C/C
> > > > > ++ compiler is main system compiler (and generally therefore the GNU C
> > > > > ++ runtime) uses anything named "libstdc++". So I'd expect
> > > > > Free/Net/OpenBSD + Linux use that naming and probably not much else.
> > > > > On other commercial UNIXes, if it does exist, it is just
> > > > > for compatibility with C++ programs compiled using g++.
> > > > 
> > > > gcc -lsdtdc++ doesn't even work on all Linux architectures, as libdstdc
> > > > ++ may require other stuff which is only pulled in implicitly by g++. 
> > > 
> > > Thanks.
> > > 
> > > > BTW, why does st/xorg need libstdc++ at all without LLVM?
> > > 
> > > Good question. I assumed it's needed by some mesa/gallium core, but
> > > I checked it now and it's only needed by (new) nv50/nvc0 driver code.
> > > 
> > 
> > I found another cases where -lstdc++ was used with gcc.
> > Updated patch below.
> 
> Thanks for tracking these down.
> 
> However, I wonder if we shouldn't try to only use the C++ compiler for
> linking when it's really necessary, e.g. for the nv50/nvc0 drivers.
> Otherwise, even assuming the resulting binaries don't depend on things
> like libstdc++ unless they're really needed, this creates an artificial
> requirement for a C++ compiler. (I realize a C++ compiler is really
> required for things like the GLSL compiler, but it should still be
> possible to build at least some of these targets without one).

With the attached patch, and with LLVM disabled:

uses c++ symbols | links against libstdc++ | name
1 1 i915_dri.so
1 1 i965_dri.so
1 1 nouveau_vieux_dri.so
1 1 r200_dri.so
1 1 r300_dri.so
1 1 r600_dri.so
1 1 radeon_dri.so
1 1 swrast_dri.so
1 1 egl/egl_gallium.so
1 1 gallium/i915_dri.so
1 1 gallium/i965_dri.so
0 0 gallium/libvdpau_r600.so
0 0 gallium/libvdpau_softpipe.so
0 0 gallium/libxatracker.so
1 1 gallium/libXvMCnouveau.so
0 0 gallium/libXvMCr600.so
0 0 gallium/libXvMCsoftpipe.so
1 1 gallium/nouveau_dri.so
1 1 gallium/r600_dri.so
1 1 gallium/swrast_dri.so
1 1 gallium/vmwgfx_dri.so
0 0 gbm/gbm_gallium_drm.so
0 0 gbm/pipe_i915.so
0 0 gbm/pipe_i965.so
1 1 gbm/pipe_nouveau.so
0 0 gbm/pipe_r600.so
0 0 gbm/pipe_vmwgfx.so

With LLVM enabled:

uses c++ symbols | links against libstdc++ | name
1 1 i915_dri.so
1 1 i965_dri.so
1 1 nouveau_vieux_dri.so
1 1 r200_dri.so
1 1 r300_dri.so
1 1 r600_dri.so
1 1 radeon_dri.so
1 1 swrast_dri.so
1 1 egl/egl_gallium.so
1 1 gallium/i915_dri.so
1 1 gallium/i965_dri.so
1 1 gallium/i965g_drv.so
0 1 gallium/libvdpau_r600.so
1 1 gallium/libvdpau_softpipe.so
1 1 gallium/libxatracker.so
1 1 gallium/libXvMCnouveau.so
0 1 gallium/libXvMCr600.so
1 1 gallium/libXvMCsoftpipe.so
1 1 gallium/modesetting_drv.so
1 1 gallium/nouveau2_drv.so
1 1 gallium/nouveau_dri.so
1 1 gallium/r600_dri.so
0 1 gallium/r600g_drv.so
1 1 gallium/swrast_dri.so
1 1 gallium/vmwgfx_dri.so
0 0 gbm/gbm_gallium_drm.so
1 1 gbm/pipe_i915.so
0 1 gbm/pipe_i965.so
1 1 gbm/pipe_nouveau.so
0 1 gbm/pipe_r600.so
1 1 gbm/pipe_vmwgfx.so


---
diff --git a/configure.ac b/configure.ac
index 49e81ad..c596164 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1719,7 +1719,7 @@ if test "x$enable_gallium_llvm" = xyes; then
     if test "x$LLVM_CONFIG" != xno; then
 	LLVM_VERSION=`$LLVM_CONFIG --version`
 	LLVM_CFLAGS=`$LLVM_CONFIG --cppflags|sed 's/-DNDEBUG\>//g'`
-	LLVM_LIBS="`$LLVM_CONFIG --libs` -lstdc++"
+	LLVM_LIBS="`$LLVM_CONFIG --libs`"
 
 	LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
 	DEFINES="$DEFINES -D__STDC_CONSTANT_MACROS"
diff --git a/src/gallium/targets/Makefile.dri b/src/gallium/targets/Makefile.dri
index 857ebfe..a26b3ee 100644
--- a/src/gallium/targets/Makefile.dri
+++ b/src/gallium/targets/Makefile.dri
@@ -4,8 +4,6 @@
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
-else
-LDFLAGS += -lstdc++
 endif
 
 MESA_MODULES = \
diff --git a/src/gallium/targets/Makefile.va b/src/gallium/targets/Makefile.va
index 7ced430..920f130 100644
--- a/src/gallium/targets/Makefile.va
+++ b/src/gallium/targets/Makefile.va
@@ -17,8 +17,13 @@ STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/va/libvatracker.a
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 # XXX: Hack, VA public funcs aren't exported
@@ -39,7 +44,7 @@ OBJECTS = $(C_SOURCES:.c=.o) \
 default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME)
 
 $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(OBJECTS) $(PIPE_DRIVERS) $(STATE_TRACKER_LIB) $(TOP)/$(LIB_DIR)/gallium Makefile
-	$(MKLIB) -o $(LIBBASENAME) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(LIBBASENAME) -linker '$(LD)' -ldflags '$(LDFLAGS)' \
 		-major $(VA_MAJOR) -minor $(VA_MINOR) $(MKLIB_OPTIONS) \
 		-install $(TOP)/$(LIB_DIR)/gallium \
 		$(OBJECTS) $(STATE_TRACKER_LIB) $(PIPE_DRIVERS) $(LIBS) $(DRIVER_EXTRAS)
diff --git a/src/gallium/targets/Makefile.vdpau b/src/gallium/targets/Makefile.vdpau
index c634915..39984e2 100644
--- a/src/gallium/targets/Makefile.vdpau
+++ b/src/gallium/targets/Makefile.vdpau
@@ -17,8 +17,13 @@ STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/vdpau/libvdpautracker.a
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 # XXX: Hack, VDPAU public funcs aren't exported if we link to libvdpautracker.a :(
@@ -39,7 +44,7 @@ OBJECTS = $(C_SOURCES:.c=.o) \
 default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME)
 
 $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(OBJECTS) $(PIPE_DRIVERS) $(STATE_TRACKER_LIB) $(TOP)/$(LIB_DIR)/gallium Makefile
-	$(MKLIB) -o $(LIBBASENAME) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(LIBBASENAME) -linker '$(LD)' -ldflags '$(LDFLAGS)' \
 		-major $(VDPAU_MAJOR) -minor $(VDPAU_MINOR) $(MKLIB_OPTIONS) \
 		-install $(TOP)/$(LIB_DIR)/gallium \
 		$(OBJECTS) $(STATE_TRACKER_LIB) $(PIPE_DRIVERS) $(LIBS) $(DRIVER_EXTRAS)
diff --git a/src/gallium/targets/Makefile.xorg b/src/gallium/targets/Makefile.xorg
index c96eded..d1231ca 100644
--- a/src/gallium/targets/Makefile.xorg
+++ b/src/gallium/targets/Makefile.xorg
@@ -29,12 +29,15 @@ INCLUDES = \
 LIBNAME_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET)
 
 ifeq ($(MESA_LLVM),1)
-LD = $(CXX)
 LDFLAGS += $(LLVM_LDFLAGS)
-USE_CXX=1
 DRIVER_LINKS += $(LLVM_LIBS) -lm -ldl
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 
@@ -43,7 +46,7 @@ endif
 default: depend $(TOP)/$(LIB_DIR)/gallium $(LIBNAME) $(LIBNAME_STAGING)
 
 $(LIBNAME): $(OBJECTS) Makefile ../Makefile.xorg $(LIBS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES)
-	$(MKLIB) -linker '$(CC)' -noprefix -o $@ $(LDFLAGS) $(OBJECTS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $(DRIVER_LINKS)
+	$(MKLIB) -linker '$(LD)' -noprefix -o $@ $(LDFLAGS) $(OBJECTS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $(DRIVER_LINKS)
 
 depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES)
 	rm -f depend
diff --git a/src/gallium/targets/Makefile.xvmc b/src/gallium/targets/Makefile.xvmc
index 7182356..cb35d3c 100644
--- a/src/gallium/targets/Makefile.xvmc
+++ b/src/gallium/targets/Makefile.xvmc
@@ -17,11 +17,15 @@ STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/xorg/xvmc/libxvmctracker.a
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
-
 # XXX: Hack, XvMC public funcs aren't exported if we link to libxvmctracker.a :(
 OBJECTS = $(C_SOURCES:.c=.o) \
 	  $(ASM_SOURCES:.S=.o) \
@@ -40,7 +44,7 @@ OBJECTS = $(C_SOURCES:.c=.o) \
 default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME)
 
 $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(OBJECTS) $(PIPE_DRIVERS) $(STATE_TRACKER_LIB) $(TOP)/$(LIB_DIR)/gallium Makefile
-	$(MKLIB) -o $(LIBBASENAME) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(LIBBASENAME) -linker '$(LD)' -ldflags '$(LDFLAGS)' \
 		-major $(XVMC_MAJOR) -minor $(XVMC_MINOR) $(MKLIB_OPTIONS) \
 		-install $(TOP)/$(LIB_DIR)/gallium \
 		$(OBJECTS) $(STATE_TRACKER_LIB) $(PIPE_DRIVERS) $(LIBS) $(DRIVER_EXTRAS)
diff --git a/src/gallium/targets/gbm/Makefile b/src/gallium/targets/gbm/Makefile
index 3f52aae..15618a6 100644
--- a/src/gallium/targets/gbm/Makefile
+++ b/src/gallium/targets/gbm/Makefile
@@ -103,48 +103,55 @@ pipe_LIBS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
 endif
 
 # determine the targets/sources
-pipe_TARGETS =
+_pipe_TARGETS_CC =
+_pipe_TARGETS_CXX =
 pipe_SOURCES =
 
 ifneq ($(findstring i915/drm,$(GALLIUM_WINSYS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)i915.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)i915.so
 pipe_SOURCES += pipe_i915.c
 endif
 
 ifneq ($(findstring i965/drm,$(GALLIUM_WINSYS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)i965.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)i965.so
 pipe_SOURCES += pipe_i965.c
 endif
 
 ifneq ($(findstring nouveau/drm,$(GALLIUM_WINSYS_DIRS)),)
-LDFLAGS += -lstdc++
-pipe_TARGETS += $(PIPE_PREFIX)nouveau.so
+_pipe_TARGETS_CXX += $(PIPE_PREFIX)nouveau.so
 pipe_SOURCES += pipe_nouveau.c
 endif
 
 ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
 ifneq ($(findstring r300,$(GALLIUM_DRIVERS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)r300.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)r300.so
 pipe_SOURCES += pipe_r300.c
 endif
 endif
 
 ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
 ifneq ($(findstring r600,$(GALLIUM_DRIVERS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)r600.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)r600.so
 pipe_SOURCES += pipe_r600.c
 endif
 endif
 
 ifneq ($(findstring svga/drm,$(GALLIUM_WINSYS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)vmwgfx.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)vmwgfx.so
 pipe_SOURCES += pipe_vmwgfx.c
 endif
 
 pipe_OBJECTS = $(pipe_SOURCES:.c=.o)
 
+ifeq ($(MESA_LLVM),1)
+pipe_TARGETS_CXX = $(_pipe_TARGETS_CXX) $(_pipe_TARGETS_CC)
+pipe_TARGETS_CC =
+else
+pipe_TARGETS_CXX = $(_pipe_TARGETS_CXX)
+pipe_TARGETS_CC = $(_pipe_TARGETS_CC)
+endif
 
-GBM_EXTRA_TARGETS = $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS))
+GBM_EXTRA_TARGETS = $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS_CC)) $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS_CXX))
 GBM_EXTRA_INSTALL = install-pipes
 GBM_EXTRA_CLEAN = clean-pipes
 GBM_EXTRA_SOURCES = $(pipe_SOURCES)
@@ -156,13 +163,20 @@ $(GBM_EXTRA_TARGETS): $(TOP)/$(LIB_DIR)/gbm/%: %
 	@$(INSTALL) -d $(dir $@)
 	$(INSTALL) $< $(dir $@)
 
-$(pipe_TARGETS): $(PIPE_PREFIX)%.so: pipe_%.o $(pipe_LIBS) $($*_LIBS)
+$(pipe_TARGETS_CC): $(PIPE_PREFIX)%.so: pipe_%.o $(pipe_LIBS) $($*_LIBS)
 	$(MKLIB) -o $@ -noprefix -linker '$(CC)' \
 		-ldflags '-L$(TOP)/$(LIB_DIR) $(pipe_LDFLAGS) $(LDFLAGS)' \
 		$(MKLIB_OPTIONS) $< \
 		-Wl,--start-group $(pipe_LIBS) $($*_LIBS) -Wl,--end-group \
 		$(pipe_SYS) $($*_SYS)
 
+$(pipe_TARGETS_CXX): $(PIPE_PREFIX)%.so: pipe_%.o $(pipe_LIBS) $($*_LIBS)
+	$(MKLIB) -o $@ -noprefix -linker '$(CXX)' \
+		-ldflags '-L$(TOP)/$(LIB_DIR) $(pipe_LDFLAGS) $(LDFLAGS)' \
+		$(MKLIB_OPTIONS) $< \
+		-Wl,--start-group $(pipe_LIBS) $($*_LIBS) -Wl,--end-group \
+		$(pipe_SYS) $($*_SYS)
+
 $(pipe_OBJECTS): %.o: %.c
 	$(CC) -c -o $@ $< $(pipe_INCLUDES) $(pipe_CFLAGS) $(CFLAGS)
 
diff --git a/src/gallium/targets/xa-vmwgfx/Makefile b/src/gallium/targets/xa-vmwgfx/Makefile
index fecdba6..5eebc50 100644
--- a/src/gallium/targets/xa-vmwgfx/Makefile
+++ b/src/gallium/targets/xa-vmwgfx/Makefile
@@ -33,8 +33,13 @@ OBJECTS = $(SOURCES:.c=.o)
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 GALLIUM_AUXILIARIES += $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 ##### RULES #####
@@ -50,7 +55,7 @@ default: $(TOP)/$(LIB_DIR)/gallium/$(XA_LIB_NAME)
 
 # Make the library
 $(TOP)/$(LIB_DIR)/gallium/$(XA_LIB_NAME): depend $(OBJECTS) $(XA_LIB_DEPS)
-	$(MKLIB) -o $(XA_LIB) -linker $(CC) -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(XA_LIB) -linker $(LD) -ldflags '$(LDFLAGS)' \
 		-major $(XA_MAJOR) -minor $(XA_MINOR) -patch $(XA_TINY) \
 		$(MKLIB_OPTIONS) \
 		-exports $(TOP)/src/gallium/state_trackers/xa/xa_symbols\
diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile
index cb4ae49..72899db 100644
--- a/src/gallium/targets/xorg-nouveau/Makefile
+++ b/src/gallium/targets/xorg-nouveau/Makefile
@@ -26,4 +26,6 @@ DRIVER_LINKS = \
 DRIVER_INCLUDES = \
 	$(shell $(PKG_CONFIG) --cflags-only-I libdrm libdrm_nouveau xf86driproto)
 
+LINK_WITH_CXX=1
+
 include ../Makefile.xorg
diff --git a/src/gallium/targets/xvmc-nouveau/Makefile b/src/gallium/targets/xvmc-nouveau/Makefile
index cc18864..67036ee 100644
--- a/src/gallium/targets/xvmc-nouveau/Makefile
+++ b/src/gallium/targets/xvmc-nouveau/Makefile
@@ -21,6 +21,8 @@ C_SOURCES = \
 
 DRIVER_LIBS = $(shell $(PKG_CONFIG) libdrm_nouveau --libs) -lXfixes
 
+LINK_WITH_CXX=1
+
 include ../Makefile.xvmc
 
 symlinks:


More information about the mesa-dev mailing list