From f869cf4908427cdae13547568135f61fc7c26014 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 11 Aug 2024 17:46:22 +0200 Subject: [PATCH 1/2] Accept pure static libraries without object files as -lib inputs --- dmd/main.d | 8 ++++---- tests/driver/merge_static_libs.d | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 tests/driver/merge_static_libs.d diff --git a/dmd/main.d b/dmd/main.d index b1588b8a0cd..327336a626a 100644 --- a/dmd/main.d +++ b/dmd/main.d @@ -786,7 +786,8 @@ version (IN_LLVM) if (global.errors) fatal(); - if (!IN_LLVM && driverParams.lib && params.objfiles.length == 0) + // IN_LLVM: with -lib, accept no object files if there are library files + if (driverParams.lib && params.objfiles.length == 0 && (!IN_LLVM || params.libfiles.length == 0)) { error(Loc.initial, "no input files"); return EXIT_FAILURE; @@ -834,12 +835,11 @@ else if (global.errors) fatal(); int status = EXIT_SUCCESS; - if (!params.objfiles.length) + // IN_LLVM: with -lib, accept no object files if there are library files (verified earlier) + if (!params.objfiles.length && (!IN_LLVM || !driverParams.lib)) { if (driverParams.link) error(Loc.initial, "no object files to link"); - if (IN_LLVM && !driverParams.link && driverParams.lib) - error(Loc.initial, "no object files"); } else { diff --git a/tests/driver/merge_static_libs.d b/tests/driver/merge_static_libs.d new file mode 100644 index 00000000000..8cd7c019bb9 --- /dev/null +++ b/tests/driver/merge_static_libs.d @@ -0,0 +1,5 @@ +// RUN: %ldc -lib %s -of=%t_1%lib +// RUN: %ldc -lib %s -of=%t_2%lib +// RUN: %ldc -lib %t_1%lib %t_2%lib -of=%t_merged%lib + +void foo() {} From a8c0550f5911c4ac62602b853fd472725d94bd41 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 11 Aug 2024 19:23:44 +0200 Subject: [PATCH 2/2] [modify test] --- tests/driver/merge_static_libs.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/driver/merge_static_libs.d b/tests/driver/merge_static_libs.d index 8cd7c019bb9..970b5df60e3 100644 --- a/tests/driver/merge_static_libs.d +++ b/tests/driver/merge_static_libs.d @@ -1,5 +1,5 @@ -// RUN: %ldc -lib %s -of=%t_1%lib -// RUN: %ldc -lib %s -of=%t_2%lib -// RUN: %ldc -lib %t_1%lib %t_2%lib -of=%t_merged%lib +// RUN: %ldc -lib %s -of=%t%lib +// RUN: %ldc -lib %t%lib -of=%t_merged%lib +// RUN: %diff_binary %t%lib %t_merged%lib void foo() {}