Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDMD: Append default file extension if -of doesn't contain any #2002

Merged
merged 6 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports # more recent CMake
packages:
- libconfig++8-dev
- gdb
Expand All @@ -51,6 +52,8 @@ addons:
- libedit2
- libedit-dev
- libcurl3:i386
- cmake
- cmake-data
before_install:
-
if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
Expand Down
5 changes: 4 additions & 1 deletion driver/cl_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ cl::list<std::string> runargs(
"Runs the resulting program, passing the remaining arguments to it"),
cl::Positional, cl::PositionalEatsArgs);

cl::opt<bool> invokedByLDMD("ldmd", cl::desc("Invoked by LDMD?"),
cl::ZeroOrMore, cl::ReallyHidden);

static cl::opt<ubyte, true> useDeprecated(
cl::desc("Allow deprecated code/language features:"), cl::ZeroOrMore,
clEnumValues(clEnumValN(0, "de", "Do not allow deprecated features"),
Expand Down Expand Up @@ -322,7 +325,7 @@ cl::opt<std::string>
#endif

cl::opt<llvm::Reloc::Model> mRelocModel(
"relocation-model", cl::desc("Relocation model"),
"relocation-model", cl::desc("Relocation model"), cl::ZeroOrMore,
#if LDC_LLVM_VER < 309
cl::init(llvm::Reloc::Default),
#endif
Expand Down
1 change: 1 addition & 0 deletions driver/cl_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern llvm::SmallVector<const char *, 32> allArguments;
*/
extern cl::list<std::string> fileList;
extern cl::list<std::string> runargs;
extern cl::opt<bool> invokedByLDMD;
extern cl::opt<bool> compileOnly;
extern cl::opt<bool, true> enforcePropertySyntax;
extern cl::opt<bool> noAsm;
Expand Down
12 changes: 4 additions & 8 deletions driver/ldmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ void translateArgs(size_t originalArgc, char **originalArgv,
assert(ldcArgs.size() == 1);
const std::string ldcPath = ldcArgs[0];

ldcArgs.push_back("-ldmd");

bool vdmd = false;
bool noFiles = true;

Expand Down Expand Up @@ -441,14 +443,8 @@ void translateArgs(size_t originalArgc, char **originalArgv,
* -wi
* -O
* -o-
*/
else if (strcmp(p + 1, "od") == 0) {
ldcArgs.push_back(p);
// DMD creates static libraries in the objects directory (unless using
// an absolute output path via `-of`).
ldcArgs.push_back("-create-static-lib-in-objdir");
}
/* -of
* -od
* -of
* -op
*/
else if (strcmp(p + 1, "o") == 0) {
Expand Down
55 changes: 30 additions & 25 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ static llvm::cl::opt<bool> staticFlag(
"Create a statically linked binary, including all system dependencies"),
llvm::cl::ZeroOrMore);

// used by LDMD
static llvm::cl::opt<bool> createStaticLibInObjdir(
"create-static-lib-in-objdir",
llvm::cl::desc("Create static library in -od directory (DMD-compliant)"),
llvm::cl::ZeroOrMore, llvm::cl::ReallyHidden);

static llvm::cl::opt<std::string>
ltoLibrary("flto-binary",
llvm::cl::desc("Set the linker LTO plugin library file (e.g. "
Expand All @@ -73,23 +67,30 @@ static void CreateDirectoryOnDisk(llvm::StringRef fileName) {
//////////////////////////////////////////////////////////////////////////////

static std::string getOutputName(bool const sharedLib) {
if (global.params.exefile)
return global.params.exefile;

// Infer output name from first object file.
std::string result = global.params.objfiles->dim
? FileName::removeExt((*global.params.objfiles)[0])
: "a.out";
const auto &triple = *global.params.targetTriple;

const char *extension = nullptr;
if (sharedLib) {
extension = global.dll_ext;
if (!global.params.targetTriple->isWindowsMSVCEnvironment())
result = "lib" + result;
} else if (global.params.targetTriple->isOSWindows()) {
} else if (triple.isOSWindows()) {
extension = "exe";
}

if (global.params.exefile) {
// DMD adds the default extension if there is none
return opts::invokedByLDMD && extension
? FileName::defaultExt(global.params.exefile, extension)
: global.params.exefile;
}

// Infer output name from first object file.
std::string result = global.params.objfiles->dim
? FileName::removeExt((*global.params.objfiles)[0])
: "a.out";

if (sharedLib && !triple.isWindowsMSVCEnvironment())
result = "lib" + result;

if (global.params.run) {
// If `-run` is passed, the executable is temporary and is removed
// after execution. Make sure the name does not collide with other files
Expand All @@ -100,11 +101,9 @@ static std::string getOutputName(bool const sharedLib) {
tempFilename);
if (!EC)
result = tempFilename.str();
} else {
if (extension) {
result += ".";
result += extension;
}
} else if (extension) {
result += '.';
result += extension;
}

return result;
Expand Down Expand Up @@ -840,15 +839,21 @@ int createStaticLibrary() {
// output filename
std::string libName;
if (global.params.libname) { // explicit
libName = global.params.libname;
// DMD adds the default extension if there is none
libName = opts::invokedByLDMD
? FileName::defaultExt(global.params.libname, global.lib_ext)
: global.params.libname;
} else { // infer from first object file
libName = global.params.objfiles->dim
? FileName::removeExt((*global.params.objfiles)[0])
: "a.out";
libName.push_back('.');
libName.append(global.lib_ext);
libName += '.';
libName += global.lib_ext;
}
if (createStaticLibInObjdir && global.params.objdir &&

// DMD creates static libraries in the objects directory (unless using an
// absolute output path via `-of`).
if (opts::invokedByLDMD && global.params.objdir &&
!FileName::absolute(libName.c_str())) {
libName = FileName::combine(global.params.objdir, libName.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ int cppmain(int argc, char **argv) {
global.dll_ext = "dll";
global.lib_ext = (global.params.mscoff ? "lib" : "a");
} else {
global.dll_ext = "so";
global.dll_ext = global.params.targetTriple->isOSDarwin() ? "dylib" : "so";
global.lib_ext = "a";
}

Expand Down
9 changes: 7 additions & 2 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(runtime)

cmake_minimum_required(VERSION 2.8.5)
cmake_minimum_required(VERSION 2.8.9)

#
# Main configuration.
Expand Down Expand Up @@ -480,7 +480,12 @@ macro(build_runtime_variants d_flags c_flags ld_flags path_suffix outlist_target
"${path_suffix}"
${outlist_targets}
)
build_profile_runtime ("${d_flags}" "${c_flags}" "${ld_flags}" "${path_suffix}" ${outlist_targets})

if(LDC_WITH_PGO)
build_profile_runtime("${d_flags};${D_FLAGS};${D_FLAGS_RELEASE}" "${c_flags}" "${ld_flags}" "${path_suffix}" ${outlist_targets})
get_target_suffix("" "${path_suffix}" target_suffix)
set_common_library_properties(ldc-profile-rt${target_suffix})
endif()
endmacro()

# Setup the build of profile-rt
Expand Down
9 changes: 1 addition & 8 deletions runtime/profile-rt/DefineBuildProfileRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ if (LDC_WITH_PGO)
if (NOT (LDC_LLVM_VER GREATER 309))
set(PROFRT_EXTRA_LDFLAGS "Ws2_32.lib")
endif()
else()
set(PROFRT_EXTRA_FLAGS "-fPIC -O3")
endif()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appropriate optimizations (for MSVC too) are already enforced - we rewrite all CMAKE_C_FLAGS_{DEBUG,MINSIZEREL,RELWITHDEBINFO} with ..._RELEASE in runtime/CMakeLists.txt (as the C parts of druntime/Phobos are always compiled in release too).

CHECK_CXX_SOURCE_COMPILES("
Expand Down Expand Up @@ -115,9 +113,4 @@ if (LDC_WITH_PGO)

# Install D interface files to profile-rt.
install(DIRECTORY ${PROFILERT_DIR}/d/ldc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")

else()
# No profiling supported, define NOP macro
macro(build_profile_runtime c_flags ld_flags path_suffix outlist_targets)
endmacro()
endif()
endif()
2 changes: 1 addition & 1 deletion tests/d2/dmd-testsuite
Submodule dmd-testsuite updated 1 files
+32 −0 compilable/ldc_output_filenames.sh