Add a -fuse-init-array option to cc1 and map to the UseInitArray target

option. On the driver, check if we are using libraries from gcc 4.7 or newer
and if so pass -fuse-init-array to the frontend.
The crtbegin*.o files in gcc 4.7 no longer call the constructors listed in
.ctors, so we have to use .init_array.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158694 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2012-06-19 01:26:10 +00:00
Родитель 0d3317e0a2
Коммит 8af669f2f1
10 изменённых файлов: 41 добавлений и 2 удалений

Просмотреть файл

@ -196,6 +196,8 @@ def mrelocation_model : Separate<"-mrelocation-model">,
HelpText<"The relocation model to use">;
def munwind_tables : Flag<"-munwind-tables">,
HelpText<"Generate unwinding tables for all functions">;
def fuse_init_array : Flag<"-fuse-init-array">,
HelpText<"Use .init_array instead of .ctors">;
def mconstructor_aliases : Flag<"-mconstructor-aliases">,
HelpText<"Emit complete constructors and destructors as aliases when possible">;
def mlink_bitcode_file : Separate<"-mlink-bitcode-file">,

Просмотреть файл

@ -230,6 +230,10 @@ public:
virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const;
// addClangTargetOptions - Add options that need to be passed to cc1 for
// this target.
virtual void addClangTargetOptions(ArgStringList &CC1Args) const;
// GetRuntimeLibType - Determine the runtime library type to use with the
// given compilation arguments.
virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const;

Просмотреть файл

@ -118,6 +118,8 @@ public:
unsigned StackRealignment : 1; ///< Control whether to permit stack
///< realignment.
unsigned UseInitArray : 1; ///< Control whether to use .init_array or
///< .ctors.
unsigned StackAlignment; ///< Overrides default stack alignment,
///< if not 0.
@ -228,6 +230,7 @@ public:
StackRealignment = 0;
StackAlignment = 0;
BoundsChecking = 0;
UseInitArray = 0;
DebugInfo = NoDebugInfo;
Inlining = NoInlining;

Просмотреть файл

@ -338,6 +338,9 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
Options.NoFramePointerElimNonLeaf = true;
}
if (CodeGenOpts.UseInitArray)
Options.UseInitArray = true;
// Set float ABI type.
if (CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp")
Options.FloatABIType = llvm::FloatABI::Soft;

Просмотреть файл

@ -189,6 +189,9 @@ void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// Each toolchain should provide the appropriate include flags.
}
void ToolChain::addClangTargetOptions(ArgStringList &CC1Args) const {
}
ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
const ArgList &Args) const
{

Просмотреть файл

@ -2116,6 +2116,12 @@ Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA,
return *T;
}
void Linux::addClangTargetOptions(ArgStringList &CC1Args) const {
const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion();
if (V >= Generic_GCC::GCCVersion::Parse("4.7.0"))
CC1Args.push_back("-fuse-init-array");
}
void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
const Driver &D = getDriver();
@ -2258,7 +2264,7 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
// equivalent to '/usr/include/c++/X.Y' in almost all cases.
StringRef LibDir = GCCInstallation.getParentLibPath();
StringRef InstallDir = GCCInstallation.getInstallPath();
StringRef Version = GCCInstallation.getVersion();
StringRef Version = GCCInstallation.getVersion().Text;
if (!addLibStdCXXIncludePaths(LibDir + "/../include/c++/" + Version,
(GCCInstallation.getTriple().str() +
GCCInstallation.getMultiarchSuffix()),

Просмотреть файл

@ -99,7 +99,7 @@ protected:
StringRef getParentLibPath() const { return GCCParentLibPath; }
/// \brief Get the detected GCC version string.
StringRef getVersion() const { return Version.Text; }
const GCCVersion &getVersion() const { return Version; }
private:
static void CollectLibDirsAndTriples(
@ -538,6 +538,7 @@ public:
virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const;
virtual void addClangTargetOptions(ArgStringList &CC1Args) const;
virtual void AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const;

Просмотреть файл

@ -1814,6 +1814,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
AsynchronousUnwindTables))
CmdArgs.push_back("-munwind-tables");
getToolChain().addClangTargetOptions(CmdArgs);
if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
CmdArgs.push_back("-mlimit-float-precision");
CmdArgs.push_back(A->getValue(Args));

Просмотреть файл

@ -1229,6 +1229,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ);
Opts.BoundsChecking = Args.getLastArgIntValue(OPT_fbounds_checking_EQ, 0,
Diags);
Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array);
Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
Opts.DataSections = Args.hasArg(OPT_fdata_sections);

Просмотреть файл

@ -0,0 +1,14 @@
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target i386-unknown-linux \
// RUN: --sysroot=%S/Inputs/fake_install_tree \
// RUN: | FileCheck --check-prefix=CHECK-GCC-4-7 %s
// CHECK-GCC-4-7: -fuse-init-array
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target i386-unknown-linux \
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
// RUN: | FileCheck --check-prefix=CHECK-GCC-4-6 %s
// CHECK-GCC-4-6-NOT: -fuse-init-array