summaryrefslogtreecommitdiff
path: root/tools/driver
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
commit2b6b257f4e5503a7a2675bdb8735693db769f75c (patch)
treee85e046ae7003fe3bcc8b5454cd0fa3f7407b470 /tools/driver
parentb4348ed0b7e90c0831b925fbee00b5f179a99796 (diff)
Notes
Diffstat (limited to 'tools/driver')
-rw-r--r--tools/driver/CMakeLists.txt35
-rw-r--r--tools/driver/Makefile75
-rw-r--r--tools/driver/cc1_main.cpp6
-rw-r--r--tools/driver/cc1as_main.cpp28
-rw-r--r--tools/driver/driver.cpp32
5 files changed, 55 insertions, 121 deletions
diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt
index fca9b616751b..e03b3fa3951e 100644
--- a/tools/driver/CMakeLists.txt
+++ b/tools/driver/CMakeLists.txt
@@ -24,7 +24,7 @@ if(CLANG_PLUGIN_SUPPORT)
set(LLVM_NO_DEAD_STRIP 1)
endif()
-add_clang_executable(clang
+add_clang_tool(clang
driver.cpp
cc1_main.cpp
cc1as_main.cpp
@@ -51,18 +51,6 @@ endif()
add_dependencies(clang clang-headers)
-install(TARGETS clang
- RUNTIME DESTINATION bin
- COMPONENT clang)
-
-if(NOT CMAKE_CONFIGURATION_TYPES)
- add_custom_target(install-clang
- DEPENDS clang
- COMMAND "${CMAKE_COMMAND}"
- -DCMAKE_INSTALL_COMPONENT=clang
- -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-endif()
-
if(NOT CLANG_LINKS_TO_CREATE)
set(CLANG_LINKS_TO_CREATE clang++ clang-cl)
@@ -99,8 +87,25 @@ if (APPLE)
set(TOOL_INFO_BUILD_VERSION)
endif()
-if(CLANG_ORDER_FILE)
- target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}")
+# the linker -order_file flag is only supported by ld64
+if(LD64_EXECUTABLE AND CLANG_ORDER_FILE)
+ include(CMakePushCheckState)
+
+ function(check_linker_flag flag out_var)
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
+ check_cxx_compiler_flag("" ${out_var})
+ cmake_pop_check_state()
+ endfunction()
+
+ # This is a test to ensure the actual order file works with the linker.
+ check_linker_flag("-Wl,-order_file,${CLANG_ORDER_FILE}"
+ LINKER_ORDER_FILE_WORKS)
+
+ if(LINKER_ORDER_FILE_WORKS)
+ target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}")
+ set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
+ endif()
endif()
if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
diff --git a/tools/driver/Makefile b/tools/driver/Makefile
deleted file mode 100644
index 347702eb9611..000000000000
--- a/tools/driver/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
-##===- tools/driver/Makefile -------------------------------*- Makefile -*-===##
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-CLANG_LEVEL := ../..
-
-TOOLNAME = clang
-TOOLALIAS = clang++
-
-ifdef CLANG_ORDER_FILE
-TOOL_ORDER_FILE := $(CLANG_ORDER_FILE)
-endif
-
-# Include tool version information on OS X.
-TOOL_INFO_PLIST := Info.plist
-
-# Include this here so we can get the configuration of the targets that have
-# been configured for construction. We have to do this early so we can set up
-# LINK_COMPONENTS before including Makefile.rules
-include $(CLANG_LEVEL)/../../Makefile.config
-
-# Have the option of not supporting plugins. This is important for startup
-# performance.
-ifeq ($(CLANG_PLUGIN_SUPPORT), 1)
-NO_DEAD_STRIP := 1
-else
-TOOL_NO_EXPORTS := 1
-endif
-
-LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader bitwriter codegen \
- instrumentation ipo irreader linker objcarcopts option \
- profiledata selectiondag
-USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \
- clangSerialization.a clangCodeGen.a clangParse.a clangSema.a \
- clangRewriteFrontend.a clangRewrite.a
-
-ifeq ($(ENABLE_CLANG_STATIC_ANALYZER),1)
-USEDLIBS += clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a \
- clangStaticAnalyzerCore.a
-endif
-
-ifeq ($(ENABLE_CLANG_ARCMT),1)
-USEDLIBS += clangARCMigrate.a
-endif
-
-USEDLIBS += clangAnalysis.a clangEdit.a clangAST.a clangLex.a clangBasic.a
-
-include $(CLANG_LEVEL)/Makefile
-
-# Set the tool version information values.
-ifeq ($(HOST_OS),Darwin)
-ifdef CLANG_VENDOR
-TOOL_INFO_NAME := $(CLANG_VENDOR) clang
-else
-TOOL_INFO_NAME := clang
-endif
-
-ifdef CLANG_VENDOR_UTI
-TOOL_INFO_UTI := $(CLANG_VENDOR_UTI)
-else
-TOOL_INFO_UTI := org.llvm.clang
-endif
-
-TOOL_INFO_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \
- $(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc))
-ifdef LLVM_SUBMIT_VERSION
-TOOL_INFO_BUILD_VERSION := $(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION)
-else
-TOOL_INFO_BUILD_VERSION :=
-endif
-endif
diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp
index 8240561236b2..d78a31e67a2f 100644
--- a/tools/driver/cc1_main.cpp
+++ b/tools/driver/cc1_main.cpp
@@ -126,15 +126,9 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
// When running with -disable-free, don't do any destruction or shutdown.
if (Clang->getFrontendOpts().DisableFree) {
- if (llvm::AreStatisticsEnabled() || Clang->getFrontendOpts().ShowStats)
- llvm::PrintStatistics();
BuryPointer(std::move(Clang));
return !Success;
}
- // Managed static deconstruction. Useful for making things like
- // -time-passes usable.
- llvm::llvm_shutdown();
-
return !Success;
}
diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp
index 59b7af521743..2d17be99e2d5 100644
--- a/tools/driver/cc1as_main.cpp
+++ b/tools/driver/cc1as_main.cpp
@@ -30,10 +30,10 @@
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCParser/MCAsmParser.h"
+#include "llvm/MC/MCParser/MCTargetAsmParser.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
-#include "llvm/MC/MCTargetAsmParser.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
@@ -43,10 +43,8 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Host.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
@@ -88,6 +86,7 @@ struct AssemblerInvocation {
unsigned SaveTemporaryLabels : 1;
unsigned GenDwarfForAssembly : 1;
unsigned CompressDebugSections : 1;
+ unsigned RelaxELFRelocations : 1;
unsigned DwarfVersion;
std::string DwarfDebugFlags;
std::string DwarfDebugProducer;
@@ -200,7 +199,8 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
// Any DebugInfoKind implies GenDwarfForAssembly.
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections);
- Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 0, Diags);
+ Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
+ Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
@@ -313,7 +313,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
// Ensure MCAsmInfo initialization occurs before any use, otherwise sections
// may be created with a combination of default and explicit settings.
if (Opts.CompressDebugSections)
- MAI->setCompressDebugSections(true);
+ MAI->setCompressDebugSections(DebugCompressionType::DCT_ZlibGnu);
+
+ MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
std::unique_ptr<raw_fd_ostream> FDOS = getOutputStream(Opts, Diags, IsBinary);
@@ -326,19 +328,18 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
- llvm::Reloc::Model RM = llvm::Reloc::Default;
+ bool PIC = false;
if (Opts.RelocationModel == "static") {
- RM = llvm::Reloc::Static;
+ PIC = false;
} else if (Opts.RelocationModel == "pic") {
- RM = llvm::Reloc::PIC_;
+ PIC = true;
} else {
assert(Opts.RelocationModel == "dynamic-no-pic" &&
"Invalid PIC model!");
- RM = llvm::Reloc::DynamicNoPIC;
+ PIC = false;
}
- MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), RM,
- CodeModel::Default, Ctx);
+ MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, CodeModel::Default, Ctx);
if (Opts.SaveTemporaryLabels)
Ctx.setAllowTemporaryLabels(false);
if (Opts.GenDwarfForAssembly)
@@ -447,11 +448,6 @@ static void LLVMErrorHandler(void *UserData, const std::string &Message,
}
int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
- // Print a stack trace if we signal out.
- sys::PrintStackTraceOnErrorSignal();
- PrettyStackTraceProgram X(Argv.size(), Argv.data());
- llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
// Initialize targets and assembly printers/parsers.
InitializeAllTargetInfos();
InitializeAllTargetMCs();
diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp
index de14425d3616..4d69aaffba23 100644
--- a/tools/driver/driver.cpp
+++ b/tools/driver/driver.cpp
@@ -130,7 +130,7 @@ static void ApplyOneQAOverride(raw_ostream &OS,
}
}
} else if (Edit[0] == 'x' || Edit[0] == 'X') {
- std::string Option = Edit.substr(1, std::string::npos);
+ auto Option = Edit.substr(1);
for (unsigned i = 1; i < Args.size();) {
if (Option == Args[i]) {
OS << "### Deleting argument " << Args[i] << '\n';
@@ -308,8 +308,9 @@ static int ExecuteCC1Tool(ArrayRef<const char *> argv, StringRef Tool) {
}
int main(int argc_, const char **argv_) {
- llvm::sys::PrintStackTraceOnErrorSignal();
+ llvm::sys::PrintStackTraceOnErrorSignal(argv_[0]);
llvm::PrettyStackTraceProgram X(argc_, argv_);
+ llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
if (llvm::sys::Process::FixupStandardFileDescriptors())
return 1;
@@ -338,18 +339,33 @@ int main(int argc_, const char **argv_) {
// have to manually search for a --driver-mode=cl argument the hard way.
// Finally, our -cc1 tools don't care which tokenization mode we use because
// response files written by clang will tokenize the same way in either mode.
- llvm::cl::TokenizerCallback Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
+ bool ClangCLMode = false;
if (TargetAndMode.second == "--driver-mode=cl" ||
std::find_if(argv.begin(), argv.end(), [](const char *F) {
return F && strcmp(F, "--driver-mode=cl") == 0;
}) != argv.end()) {
- Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
+ ClangCLMode = true;
+ }
+ enum { Default, POSIX, Windows } RSPQuoting = Default;
+ for (const char *F : argv) {
+ if (strcmp(F, "--rsp-quoting=posix") == 0)
+ RSPQuoting = POSIX;
+ else if (strcmp(F, "--rsp-quoting=windows") == 0)
+ RSPQuoting = Windows;
}
// Determines whether we want nullptr markers in argv to indicate response
- // files end-of-lines. We only use this for the /LINK driver argument.
- bool MarkEOLs = true;
- if (argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
+ // files end-of-lines. We only use this for the /LINK driver argument with
+ // clang-cl.exe on Windows.
+ bool MarkEOLs = ClangCLMode;
+
+ llvm::cl::TokenizerCallback Tokenizer;
+ if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode))
+ Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
+ else
+ Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
+
+ if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
MarkEOLs = false;
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
@@ -482,8 +498,6 @@ int main(int argc_, const char **argv_) {
// results now. This happens in -disable-free mode.
llvm::TimerGroup::printAll(llvm::errs());
- llvm::llvm_shutdown();
-
#ifdef LLVM_ON_WIN32
// Exit status should not be negative on Win32, unless abnormal termination.
// Once abnormal termiation was caught, negative status should not be