On Fri, Nov 29, 2013 at 11:22 AM, H.J. Lu <[email protected]> wrote:
> On Mon, Nov 18, 2013 at 6:44 AM, Marek Polacek <[email protected]> wrote:
>> On Mon, Nov 18, 2013 at 02:51:41PM +0100, Jakub Jelinek wrote:
>>> On Wed, Nov 13, 2013 at 12:13:48AM +0100, Marek Polacek wrote:
>>> > --- gcc/config/bootstrap-ubsan.mk.mp 2013-11-12 13:46:13.345182065
>>> > +0100
>>> > +++ gcc/config/bootstrap-ubsan.mk 2013-11-12 13:46:49.812314016 +0100
>>> > @@ -2,6 +2,6 @@
>>> >
>>> > STAGE2_CFLAGS += -fsanitize=undefined
>>> > STAGE3_CFLAGS += -fsanitize=undefined
>>> > -POSTSTAGE1_LDFLAGS += -fsanitize=undefined -static-libubsan -lpthread \
>>> > +POSTSTAGE1_LDFLAGS += -fsanitize=undefined -static-libubsan -lpthread
>>> > -ldl \
>>>
>>> Hopefully with my pending patch you can remove the -lpthread -ldl again, but
>>> ok for now.
>>
>
> You shouldn't use -ldl directly. Not all OSes have libdl. You
> should extract the libdl check from gcc/configure.ac and
> set LIBDL instead by changing gcc/Makefile.in
>
> PLUGINLIBS = @pluginlibs@
>
> to
>
> LIBDL = @libdl@
> PLUGINLIBS = @pluginlibs@ $(LIBD)
>
> Then you can use
>
> POSTSTAGE1_LDFLAGS += -fsanitize=undefined -static-libubsan -lpthread
> $(LIBDL) \
>
Something like this. Only tested with normal build.
--
H.J.
---
diff --git a/config/bootstrap-ubsan.mk b/config/bootstrap-ubsan.mk
index 0cd8b17..c298cd1 100644
--- a/config/bootstrap-ubsan.mk
+++ b/config/bootstrap-ubsan.mk
@@ -2,6 +2,7 @@
STAGE2_CFLAGS += -fsanitize=undefined
STAGE3_CFLAGS += -fsanitize=undefined
-POSTSTAGE1_LDFLAGS += -fsanitize=undefined -static-libubsan -lpthread -ldl \
+POSTSTAGE1_LDFLAGS += -fsanitize=undefined -static-libubsan -lpthread \
+ $(LIBDL) \
-B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/ubsan/ \
-B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/ubsan/.libs
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 4d683a0..cb64241 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -340,12 +340,15 @@ CLOOGINC = @CLOOGINC@
# Set to 'yes' if the LTO front end is enabled.
enable_lto = @enable_lto@
+# Library for dlopen
+LIBDL=@libdl@
+
# Compiler and flags needed for plugin support
PLUGINCC = @CXX@
PLUGINCFLAGS = @CXXFLAGS@
# Libs and linker options needed for plugin support
-PLUGINLIBS = @pluginlibs@
+PLUGINLIBS = @pluginlibs@ $(LIBDL)
enable_plugin = @enable_plugin@
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 91a22d5..80cd248 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5404,14 +5404,6 @@ if test x"$enable_plugin" = x"yes"; then
AC_MSG_RESULT([unable to check])
fi
- # Check -ldl
- saved_LIBS="$LIBS"
- AC_SEARCH_LIBS([dlopen], [dl])
- if test x"$ac_cv_search_dlopen" = x"-ldl"; then
- pluginlibs="$pluginlibs -ldl"
- fi
- LIBS="$saved_LIBS"
-
# Check that we can build shared objects with -fPIC -shared
saved_LDFLAGS="$LDFLAGS"
saved_CFLAGS="$CFLAGS"
@@ -5454,6 +5446,16 @@ if test x"$enable_plugin" = x"yes"; then
AC_DEFINE(ENABLE_PLUGIN, 1, [Define to enable plugin support.])
fi
+# Check -ldl
+libdl=
+saved_LIBS="$LIBS"
+AC_SEARCH_LIBS([dlopen], [dl])
+if test x"$ac_cv_search_dlopen" = x"-ldl"; then
+ libdl="-ldl"
+fi
+LIBS="$saved_LIBS"
+AC_SUBST(libdl)
+
# Enable --enable-host-shared
AC_ARG_ENABLE(host-shared,