[cfe-commits] [patch] Add support for different libstdc++ search path with -m32 and -m64

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Mon Oct 12 11:53:59 PDT 2009


On 10.10.2009 16:07, Rafael Espindola wrote:
> The attached patch adds support for having different search paths for
> libstdc++ in -m32 and -m64. The only targets that actually use it so
> far are darwin10 (...i686-apple-darwin10/x86_64
>  and  ..i686-apple-darwin10) and ubuntu 64 bits (...x86_64-linux-gnu
> and ...x86_64-linux-gnu/32). All other target should be unaffected.
>
> It would be very nice if people with other systems could run
>
> gcc -v  -m32 t.cc 2>&1 | sed -n '/^ /p' | sed -n 2,3p
> and
> gcc -v  -m64 t.cc 2>&1 | sed -n '/^ /p' | sed -n 2,3p
>   

Sure thing.
openSUSE 11.1, 64bit:
# gcc -v  -m32 t.cc 2>&1 | sed -n '/^ /p' | sed -n 2,3p
 /usr/include/c++/4.3
 /usr/include/c++/4.3/x86_64-suse-linux/32
gcc -v  -m64 t.cc 2>&1 | sed -n '/^ /p' | sed -n 2,3p
 /usr/include/c++/4.3
 /usr/include/c++/4.3/x86_64-suse-linux
Please note that the "32" in the path for -m32 is a symlink to the
directory it is in and thus superfluous, so removing it would yield the
paths we have now.

> --- a/lib/Frontend/InitHeaderSearch.cpp
> +++ b/lib/Frontend/InitHeaderSearch.cpp
> @@ -99,10 +99,18 @@ void InitHeaderSearch::AddEnvVarPaths(const char *Name) {
>  }
>  
>  void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(const std::string &Base,
> -                                                  const char *Arch) {
> -    AddPath(Base, System, true, false, false);
> -    AddPath(Base + "/" + Arch, System, true, false, false);
> -    AddPath(Base + "/backward", System, true, false, false);
> +                                                   const char *Dir32,
> +                                                   const char *Dir64,
> +                                                   const llvm::Triple &triple) {
> +  llvm::Triple::ArchType arch = triple.getArch();
> +  bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
> +
> +  AddPath(Base, System, true, false, false);
> +  if (is64bit)
> +    AddPath(Base + "/" + Dir64, System, true, false, false);
> +  else
> +    AddPath(Base + "/" + Dir32, System, true, false, false);
> +  AddPath(Base + "/backward", System, true, false, false);
>  }
>  
>  #if defined(LLVM_ON_WIN32)
> @@ -222,7 +230,7 @@ bool getVisualStudioDir(std::string &path) {
>  #endif // LLVM_ON_WIN32
>  
>  void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
> -                                                   const llvm::Triple &triple) {
> +                                                    const llvm::Triple &triple) {
>    // FIXME: temporary hack: hard-coded paths.
>    llvm::Triple::OSType os = triple.getOS();
>  
> @@ -267,21 +275,15 @@ void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
>    case llvm::Triple::MinGW64:
>      if (Lang.CPlusPlus) {
>        // Try gcc 4.4.0
> -      // FIXME: This can just use AddGnuCPlusPlusIncludePaths, right?
> -      AddPath("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++",
> -              System, true, false, false);
> -      AddPath("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++/mingw32",
> -              System, true, false, false);
> -      AddPath("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++/backward",
> -              System, true, false, false);
> +      AddGnuCPlusPlusIncludePaths("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++",
> +                                  "mingw32",
> +                                  "mingw32",
> +                                  triple);
>        // Try gcc 4.3.0
> -      // FIXME: This can just use AddGnuCPlusPlusIncludePaths, right?
> -      AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++",
> -              System, true, false, false);
> -      AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/mingw32",
> -              System, true, false, false);
> -      AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/backward",
> -              System, true, false, false);
> +      AddGnuCPlusPlusIncludePaths("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++",
> +                                  "mingw32",
> +                                  "mingw32",
> +                                  triple);
>      }
>      AddPath("c:/mingw/include", System, true, false, false);
>      break;
> @@ -290,56 +292,91 @@ void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
>        switch (os) {
>          case llvm::Triple::Darwin:
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
> -                                      "i686-apple-darwin10");
> +                                      "i686-apple-darwin10",
> +                                      "i686-apple-darwin10/x86_64",
> +                                      triple);
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
> -                                      "i686-apple-darwin8");
> +                                      "i686-apple-darwin8",
> +                                      "i686-apple-darwin8",
> +                                      triple);
>            break;
>          case llvm::Triple::Linux:
>            // Ubuntu 7.10 - Gutsy Gibbon
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3",
> -                                      "i486-linux-gnu");
> +                                      "i486-linux-gnu",
> +                                      "i486-linux-gnu",
> +                                      triple);
>            // Ubuntu 9.04
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3",
> -                                      "x86_64-linux-gnu");
> +                                      "x86_64-linux-gnu/32",
> +                                      "x86_64-linux-gnu",
> +                                      triple);
>            // Fedora 8
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2",
> -                                      "i386-redhat-linux");
> +                                      "i386-redhat-linux",
> +                                      "i386-redhat-linux",
> +                                      triple);
>            // Fedora 9
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0",
> -                                      "i386-redhat-linux");
> +                                      "i386-redhat-linux",
> +                                      "i386-redhat-linux",
> +                                      triple);
>            // Fedora 10
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2",
> -                                      "i386-redhat-linux");
> -          // openSUSE 11.1
> +                                      "i386-redhat-linux",
> +                                      "i386-redhat-linux",
> +                                      triple);
> +          // openSUSE 11.1 32 bit
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
> -                                      "i586-suse-linux");
> +                                      "i586-suse-linux",
> +                                      "i586-suse-linux",
> +                                      triple);
> +          // openSUSE 11.1 64 bit
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
> -                                      "x86_64-suse-linux");
> +                                      "x86_64-suse-linux",
> +                                      "x86_64-suse-linux",
> +                                      triple);
>            // openSUSE 11.2
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
> -                                      "i586-suse-linux");
> +                                      "i586-suse-linux",
> +                                      "i586-suse-linux",
> +                                      triple);
>            AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
> -                                      "x86_64-suse-linux");
> +                                      "x86_64-suse-linux",
> +                                      "x86_64-suse-linux",
> +                                      triple);
>   

I have to admit that I don't understand why you need one entry for
openSUSE 11.2 32bit and one for 64bit. Doesn't the new
AddGnuCPlusPlusIncludePaths have the parameters to merge these two
entries? Same applies to the openSUSE 11.1 entries. Or is this all about
the compiler target arch instead of the OS arch? Then it would make sense.

Regards,
Carl-Daniel

-- 
Developer quote of the week: 
"We are juggling too many chainsaws and flaming arrows and tigers."




More information about the cfe-commits mailing list