[PATCH][Solaris] Default to -fno-cxa-finalize

Xan López via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 7 10:42:58 PDT 2015


On Mon, Sep 07, 2015 at 10:38:08AM -0700, Saleem Abdulrasool wrote:
> The patch LGTM with a minor request for tweaking the commit message to have
> the context about the fact that cxa_finalize.o never shipped, and so this
> doesn't really cause any problems for older releases.

Right. Tried to explain a bit what's going on in the commit message,
with a reference to the original commit that removed the flag.

> 
> 
> > Xan
> >
> > On Mon, Sep 07, 2015 at 09:14:05AM -0700, Saleem Abdulrasool wrote:
> > > On Mon, Sep 7, 2015 at 2:28 AM, Xan López <xan at igalia.com> wrote:
> > >
> > > > On Sat, Sep 05, 2015 at 12:25:28PM -0700, Saleem Abdulrasool wrote:
> > > > > > Ping?
> > > > > >
> > > > >
> > > > > Does this break with older Solaris releases?  How far back did this
> > > > change
> > > > > in Solaris?  The change itself should really be accompanied with a
> > test.
> > > >
> > > > Hi,
> > > >
> > > > turns out I'm not really sure cxa_finalize.o was ever available on
> > > > Solaris. The initial code for Solaris was pushed in 2012, but it was
> > > > hardcoded to work on a pretty specific Solaris/x86 environment. One
> > > > commit from that time is r151648, which claims -fno-cxa-atexit
> > > > produces broken code and says they'll ship their own
> > > > cxa_finalize.o. So it seems it was not available back then
> > > > either. I've also seen commits in OpenSolaris from 2013 creating dummy
> > > > cxa_finalize.o files so that clang will pass the bare minimum tests.
> > > >
> > >
> > > That seems less than ideal.  If there seems to be no release of Solaris
> > > with this mythical support file, it doesn't seem too terrible to just get
> > > rid of it.
> > >
> > >
> > > > Now that I'm slowly pushing changes to make clang/Solaris work again
> > > > (it was totally broken) I've found this issue again. My patch allows
> > > > me to compile clang with clang itself, and other simple C++ programs
> > > > compile and work. So if there was a bug here it was either fixed or I
> > > > have not found it yet. I'd say that we should probably fix whatever
> > > > issue there is with -fno-cxa-atexit when it shows up instead of
> > > > working around it, or maybe *actually* bundle an implementation for
> > > > Solaris with clang itself? But suggestions are welcome.
> > > >
> > >
> > > Okay, so, AIUI, no release ever contained this file, __cxa_exit isn't
> > > provided, and that using -fno-cxa-exit does (and really should) works
> > well
> > > enough for non-trivial applications.
> > >
> > >
> > > > Also, what kind of test would you have in mind for this?
> > >
> > >
> > > That -fno-cxa-exit is included by the driver when compiling for Solaris.
> > >
> > >
> > > >
> > > > Xan
> > > >
> > > > >
> > > > >
> > > > > > > From 014ddb164689a3452b76f85079f213d607d07840 Mon Sep 17 00:00:00
> > > > 2001
> > > > > > > From: =?UTF-8?q?Xan=20L=C3=B3pez?= <xan at igalia.com>
> > > > > > > Date: Fri, 14 Aug 2015 11:36:56 +0200
> > > > > > > Subject: [PATCH 2/4] [Solaris] Default to -fno-cxa-finalize
> > > > > > >
> > > > > > > There is no __cxa_finalize symbol available on recent Solaris OS
> > > > > > > versions, so we need this flag to make non trivial C++ programs
> > run.
> > > > > > >
> > > > > > > Also stop looking for cxa_finalize.o, since it won't be there.
> > > > > > > ---
> > > > > > >  lib/Driver/Tools.cpp | 9 +++------
> > > > > > >  1 file changed, 3 insertions(+), 6 deletions(-)
> > > > > > >
> > > > > > > diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
> > > > > > > index b204961..cf01d7b 100644
> > > > > > > --- a/lib/Driver/Tools.cpp
> > > > > > > +++ b/lib/Driver/Tools.cpp
> > > > > > > @@ -4506,8 +4506,9 @@ void Clang::ConstructJob(Compilation &C,
> > const
> > > > > > JobAction &JA,
> > > > > > >    if (!Args.hasFlag(options::OPT_fuse_cxa_atexit,
> > > > > > >                      options::OPT_fno_use_cxa_atexit,
> > > > > > >                      !IsWindowsCygnus && !IsWindowsGNU &&
> > > > > > > -                        getToolChain().getArch() !=
> > > > > > llvm::Triple::hexagon &&
> > > > > > > -                        getToolChain().getArch() !=
> > > > > > llvm::Triple::xcore) ||
> > > > > > > +                    getToolChain().getTriple().getOS() !=
> > > > > > llvm::Triple::Solaris &&
> > > > > > > +                    getToolChain().getArch() !=
> > > > llvm::Triple::hexagon &&
> > > > > > > +                    getToolChain().getArch() !=
> > > > llvm::Triple::xcore) ||
> > > > > > >        KernelOrKext)
> > > > > > >      CmdArgs.push_back("-fno-use-cxa-atexit");
> > > > > > >
> > > > > > > @@ -6882,10 +6883,6 @@ void
> > solaris::Linker::ConstructJob(Compilation
> > > > > > &C, const JobAction &JA,
> > > > > > >
> > > > Args.MakeArgString(getToolChain().GetFilePath("values-Xa.o")));
> > > > > > >      CmdArgs.push_back(
> > > > > > >
> > > > Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
> > > > > > > -
> > > > > > > -    if (getToolChain().getDriver().CCCIsCXX())
> > > > > > > -      CmdArgs.push_back(
> > > > > > > -
> > > > > > Args.MakeArgString(getToolChain().GetFilePath("cxa_finalize.o")));
> > > > > > >    }
> > > > > > >
> > > > > > >    const ToolChain::path_list &Paths =
> > getToolChain().getFilePaths();
> > > > > > > --
> > > > > > > 2.4.3
> > > > > > >
> > > > > >
> > > > > > > _______________________________________________
> > > > > > > cfe-commits mailing list
> > > > > > > cfe-commits at lists.llvm.org
> > > > > > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> > > > > >
> > > > > > _______________________________________________
> > > > > > cfe-commits mailing list
> > > > > > cfe-commits at lists.llvm.org
> > > > > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Saleem Abdulrasool
> > > > > compnerd (at) compnerd (dot) org
> > > >
> > >
> > >
> > >
> > > --
> > > Saleem Abdulrasool
> > > compnerd (at) compnerd (dot) org
> >
> 
> 
> 
> -- 
> Saleem Abdulrasool
> compnerd (at) compnerd (dot) org
-------------- next part --------------
>From 55a210f942f32eb9f103c44b403c548bd04841c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Xan=20L=C3=B3pez?= <xan at igalia.com>
Date: Fri, 14 Aug 2015 11:36:56 +0200
Subject: [PATCH] [Solaris] Default to -fno-cxa-finalize

There is no __cxa_finalize symbol available on Solaris, so stop
looking for cxa_finalize.o and add -fno-use-cxa-atexit as
default. Years ago this was reverted (r151648) because
-fno-use-cxa-atexit was apparently broken, but it seems to work fine
now. In any case we'd need to ship an implementation to be able to use
the feature, otherwise we'll just fail to link C++ programs.
---
 lib/Driver/Tools.cpp       | 9 +++------
 test/Driver/solaris-opts.c | 4 ++++
 2 files changed, 7 insertions(+), 6 deletions(-)
 create mode 100644 test/Driver/solaris-opts.c

diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index a15d86c..a4d6ee8 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -4575,8 +4575,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   if (!Args.hasFlag(options::OPT_fuse_cxa_atexit,
                     options::OPT_fno_use_cxa_atexit,
                     !IsWindowsCygnus && !IsWindowsGNU &&
-                        getToolChain().getArch() != llvm::Triple::hexagon &&
-                        getToolChain().getArch() != llvm::Triple::xcore) ||
+                    getToolChain().getTriple().getOS() != llvm::Triple::Solaris &&
+                    getToolChain().getArch() != llvm::Triple::hexagon &&
+                    getToolChain().getArch() != llvm::Triple::xcore) ||
       KernelOrKext)
     CmdArgs.push_back("-fno-use-cxa-atexit");
 
@@ -6948,10 +6949,6 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
         Args.MakeArgString(getToolChain().GetFilePath("values-Xa.o")));
     CmdArgs.push_back(
         Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
-
-    if (getToolChain().getDriver().CCCIsCXX())
-      CmdArgs.push_back(
-          Args.MakeArgString(getToolChain().GetFilePath("cxa_finalize.o")));
   }
 
   const ToolChain::path_list &Paths = getToolChain().getFilePaths();
diff --git a/test/Driver/solaris-opts.c b/test/Driver/solaris-opts.c
new file mode 100644
index 0000000..8c54ae0
--- /dev/null
+++ b/test/Driver/solaris-opts.c
@@ -0,0 +1,4 @@
+// RUN: %clang %s --target=sparc-sun-solaris2.11 -### -o %t.o 2>&1 | FileCheck %s
+
+// CHECK: "-fno-use-cxa-atexit"
+
-- 
2.4.3



More information about the cfe-commits mailing list