diff --git a/tools/ccc/ccclib/HostInfo.py b/tools/ccc/ccclib/HostInfo.py index d1ec28d0b3..917dc95131 100644 --- a/tools/ccc/ccclib/HostInfo.py +++ b/tools/ccc/ccclib/HostInfo.py @@ -47,7 +47,7 @@ class DarwinHostInfo(HostInfo): self.darwinVersion, self.gccVersion) - return ToolChain.Generic_GCC_ToolChain(self.driver, arch) + return ToolChain.Darwin_GCC_ToolChain(self.driver, arch) class DarwinPPCHostInfo(DarwinHostInfo): def getArchName(self, args): diff --git a/tools/ccc/ccclib/ToolChain.py b/tools/ccc/ccclib/ToolChain.py index aa1646a5b5..cda9408379 100644 --- a/tools/ccc/ccclib/ToolChain.py +++ b/tools/ccc/ccclib/ToolChain.py @@ -86,6 +86,11 @@ class ToolChain(object): def isMathErrnoDefault(self): return True + def getRelocationModel(self, picEnabled, picDisabled): + if picEnabled: + return 'pic' + return 'static' + class Darwin_X86_ToolChain(ToolChain): def __init__(self, driver, archName, darwinVersion, gccVersion): super(Darwin_X86_ToolChain, self).__init__(driver, archName) @@ -224,6 +229,17 @@ class Darwin_X86_ToolChain(ToolChain): def isMathErrnoDefault(self): return False + def getRelocationModel(self, picEnabled, picDisabled): + if self.archName == 'x86_64': + return 'pic' + + if picEnabled: + return 'pic' + elif picDisabled: + return 'static' + else: + return 'dynamic-no-pic' + class Generic_GCC_ToolChain(ToolChain): """Generic_GCC_ToolChain - A tool chain using the 'gcc' command to perform all subcommands; this relies on gcc translating the @@ -251,3 +267,13 @@ class Generic_GCC_ToolChain(ToolChain): return self.clangTool return self.toolMap[action.phase.__class__] + +class Darwin_GCC_ToolChain(Generic_GCC_ToolChain): + def getRelocationModel(self, picEnabled, picDisabled): + if picEnabled: + return 'pic' + elif picDisabled: + return 'static' + else: + return 'dynamic-no-pic' + diff --git a/tools/ccc/ccclib/Tools.py b/tools/ccc/ccclib/Tools.py index c1146a0fb2..3c80861b11 100644 --- a/tools/ccc/ccclib/Tools.py +++ b/tools/ccc/ccclib/Tools.py @@ -252,17 +252,11 @@ class Clang_CompileTool(Tool): picEnabled = (arglist.getLastArg(arglist.parser.f_PICOption) or arglist.getLastArg(arglist.parser.f_picOption) or arglist.getLastArg(arglist.parser.f_PIEOption) or - arglist.getLastArg(arglist.parser.f_pieOption) or - (not arglist.getLastArg(arglist.parser.m_kernelOption) and - not arglist.getLastArg(arglist.parser.staticOption) and - not arglist.getLastArg(arglist.parser.m_dynamicNoPicOption))) - - # FIXME: This needs to tie into a platform hook. - if (self.toolChain.archName == 'x86_64' or - picEnabled): - cmd_args.append('--relocation-model=pic') - elif not arglist.getLastArg(arglist.parser.m_dynamicNoPicOption): - cmd_args.append('--relocation-model=static') + arglist.getLastArg(arglist.parser.f_pieOption)) + picDisabled = (arglist.getLastArg(arglist.parser.m_kernelOption) or + arglist.getLastArg(arglist.parser.staticOption)) + model = self.toolChain.getRelocationModel(picEnabled, picDisabled) + cmd_args.append('--relocation-model=%s' % model) if arglist.getLastArg(arglist.parser.f_timeReportOption): cmd_args.append('--time-passes') diff --git a/tools/ccc/test/ccc/universal-hello.c b/tools/ccc/test/ccc/universal-hello.c index 480a330436..1645b1aefc 100644 --- a/tools/ccc/test/ccc/universal-hello.c +++ b/tools/ccc/test/ccc/universal-hello.c @@ -8,7 +8,7 @@ // RUN: xcc -ccc-print-phases -### -arch ppc -arch ppc %s | grep linker- | count 1 && // Check that -ccc-clang-archs is honored. -// RUN: xcc -ccc-clang-archs i386 -### -arch ppc -arch i386 %s 2>&1 | grep clang | count 1 +// RUN: xcc -ccc-clang-archs i386 -### -arch ppc -arch i386 %s 2>&1 | grep 'clang"' | count 1 int main() { printf("Hello, World!\n");