Bug 20244 – New dmd option -preview=noXlinker does not work on Linux to build a simple D application

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-09-26T02:00:32Z
Last change time
2019-09-26T06:44:26Z
Keywords
pull
Assigned to
No Owner
Creator
Alan.W.Irwin1234
Blocks
6952

Comments

Comment #0 by Alan.W.Irwin1234 — 2019-09-26T02:00:32Z
I built dmd from git master branch HEAD today to evaluate this option, and unfortunately it failed on my first test which was as follows: software@merlin> cat >main.d import std.stdio; void main() { writeln("Hello, world without explicit compilations!"); } Build and run the example without the -preview=noXlinker option to demonstrate my built version of dmd is working correctly without this flag for this source code software@merlin> /home/software/dmd/install/linux/bin64/dmd main.d software@merlin> ./main Hello, world without explicit compilations! Now attempt to build with the -preview=noXlinker option software@merlin> /home/software/dmd/install/linux/bin64/dmd -preview=noXlinker main.d gcc: error: unrecognized command line option ‘--export-dynamic’; did you mean ‘-export-dynamic’? Error: linker exited with status 1 Try again with more verbose output to see what the underlying gcc command is software@merlin> /home/software/dmd/install/linux/bin64/dmd -preview=noXlinker main.d -v predefs DigitalMars Posix linux ELFv1 CRuntime_Glibc CppRuntime_Gcc LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 D_LP64 D_PIC assert D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat binary /home/software/dmd/install/linux/bin64/dmd version v2.088.0-238-g73f37547d config /home/software/dmd/install/linux/bin64/dmd.conf DFLAGS -I/home/software/dmd/install/linux/bin64/../../src/phobos -I/home/software/dmd/install/linux/bin64/../../src/druntime/import -L-L/home/software/dmd/install/linux/bin64/../lib64 -L--export-dynamic -fPIC parse main importall main import object (/home/software/dmd/install/linux/bin64/../../src/druntime/import/object.d) import core.internal.hash (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/hash.d) import core.internal.traits (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/traits.d) import core.internal.convert (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/convert.d) import core.internal.entrypoint (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/entrypoint.d) import core.internal.array.appending (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/appending.d) import core.internal.array.comparison (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/comparison.d) import core.internal.array.equality (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/equality.d) import core.internal.array.casting (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/casting.d) import core.internal.array.concatenation (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/concatenation.d) import core.internal.array.construction (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/construction.d) import core.internal.array.capacity (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/array/capacity.d) import core.internal.dassert (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/dassert.d) import core.internal.destruction (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/destruction.d) import core.internal.moving (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/moving.d) import core.internal.postblit (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/postblit.d) import core.internal.switch_ (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/switch_.d) import std.stdio (/home/software/dmd/install/linux/bin64/../../src/phobos/std/stdio.d) import core.stdc.stddef (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/stddef.d) import std.algorithm.mutation (/home/software/dmd/install/linux/bin64/../../src/phobos/std/algorithm/mutation.d) import std.traits (/home/software/dmd/install/linux/bin64/../../src/phobos/std/traits.d) import std.meta (/home/software/dmd/install/linux/bin64/../../src/phobos/std/meta.d) import std.range.primitives (/home/software/dmd/install/linux/bin64/../../src/phobos/std/range/primitives.d) import std.functional (/home/software/dmd/install/linux/bin64/../../src/phobos/std/functional.d) import std.typecons (/home/software/dmd/install/linux/bin64/../../src/phobos/std/typecons.d) import std.format (/home/software/dmd/install/linux/bin64/../../src/phobos/std/format.d) import core.vararg (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/vararg.d) import core.stdc.stdarg (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/stdarg.d) import core.stdc.stdlib (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/stdlib.d) import core.stdc.config (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/config.d) import std.exception (/home/software/dmd/install/linux/bin64/../../src/phobos/std/exception.d) import std.internal.attributes (/home/software/dmd/install/linux/bin64/../../src/phobos/std/internal/attributes.d) import core.stdc.stdio (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/stdio.d) import core.stdc.stdint (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/stdint.d) import core.stdc.signal (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/signal.d) import core.stdc.wchar_ (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/wchar_.d) import core.stdc.time (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/time.d) import core.sys.posix.sys.types (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/sys/posix/sys/types.d) import core.sys.posix.config (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/sys/posix/config.d) semantic main import core.atomic (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/atomic.d) import core.internal.attributes (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/attributes.d) import core.internal.atomic (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/atomic.d) import core.stdc.errno (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/errno.d) entry main main.d semantic2 main semantic3 main import std.utf (/home/software/dmd/install/linux/bin64/../../src/phobos/std/utf.d) import core.exception (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/exception.d) import core.internal.string (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/internal/string.d) import std.algorithm.comparison (/home/software/dmd/install/linux/bin64/../../src/phobos/std/algorithm/comparison.d) import core.stdc.string (/home/software/dmd/install/linux/bin64/../../src/druntime/import/core/stdc/string.d) code main function D main function main._d_cmain!().main function std.stdio.writeln!string.writeln function std.stdio.File.LockingTextWriter.put!string.put function std.stdio.File.LockingTextWriter.put!string.put.__dgliteral2 function std.stdio.trustedFwrite!char.trustedFwrite function std.exception.enforce!(ErrnoException).enforce!int.enforce function std.exception.bailOut!(ErrnoException).bailOut function object.idup!(const(char)).idup function object._trustedDup!(const(char), immutable(char))._trustedDup function object._dup!(const(char), immutable(char))._dup function object._doPostblit!(immutable(char))._doPostblit function object._getPostblit!(immutable(char))._getPostblit function std.stdio.File.LockingTextWriter.put!(immutable(char)).put function std.stdio.File.LockingTextWriter.put!(immutable(char)).put.trustedFPUTC function std.stdio.File.LockingTextWriter.put!(immutable(char)).put.trustedFPUTWC function std.stdio.File.LockingTextWriter.put!char.put function std.stdio.File.LockingTextWriter.put!char.put.trustedFPUTC function std.stdio.File.LockingTextWriter.put!char.put.trustedFPUTWC gcc main.o -o main -m64 --export-dynamic -L/home/software/dmd/install/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl gcc: error: unrecognized command line option ‘--export-dynamic’; did you mean ‘-export-dynamic’? Error: linker exited with status 1 Try that gcc command with -Xlinker in front of that --export-dynamic option software@merlin> gcc main.o -o main -m64 -Xlinker --export-dynamic -L/home/software/dmd/install/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl software@merlin> ./main Hello, world without explicit compilations! I am pretty sure from these results that the implementation of this new option has a list of gcc flags that are internally generated by dmd on Linux that must have the -Xlinker option preceding them. Obviously from the above results -Bstatic and -Bdynamic are on that list. So it appears to me the fix for this issue would be to add --export-dynamic (note the two leading hyphens) to that list. I really do need this flag so I hope this fix is given some priority.
Comment #1 by Alan.W.Irwin1234 — 2019-09-26T03:10:02Z
Further investigation showed this peculiar result software@merlin> /home/software/dmd/install/linux/bin64/dmd -preview=noXlinker main.d -L-Xlinker -L-Iwhatever -v |& tail -3 gcc main.o -o main -m64 -Iwhatever -Iwhatever --export-dynamic -L/home/software/dmd/install/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl gcc: error: unrecognized command line option ‘--export-dynamic’; did you mean ‘-export-dynamic’? Error: linker exited with status 1 Why does the gcc command generated by dmd have two -Iwhatever options rather than what I expected which was -Xlinker -Iwhatever (which obviously would have generated its own error by passing -Iwhatever to ld, but that is not the point of this additional test).
Comment #2 by pro.mathias.lang — 2019-09-26T04:18:09Z
You might want to check the content of your config file (/home/software/dmd/install/linux/bin64/dmd.conf). I'd wager the "--export-dynamic" is there, in which case you can prevent it from being read by using `-conf=''`. Alternatively you can just modify your config file if you plan on always using this option.
Comment #3 by slavo5150 — 2019-09-26T04:21:40Z
That's correct. The `--export-dynamic` option is coming from the config file. Therefore if you use `-preview=noXlinker` you'll need to compensate by adding the `-Xlinker` argument to the dmd.conf file. This dmd.conf file works for me when compiling with `-preview=noXlinker` [Environment32] DFLAGS=-I%@P%/../../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/linux/release/32 -L-Xlinker -L-L--export-dynamic [Environment64] DFLAGS=-I%@P%/../../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/linux/release/64 -L-Xlinker -L-L--export-dynamic -fPIC
Comment #4 by slavo5150 — 2019-09-26T05:00:42Z
I'm sorry, but there is a bug in the implementation. When you add `-L-Xlinker -L--export-dynamic` to the dmd.conf file or command line, it actually appends `--export-dynamic --export-dynamic` instead of `-Xlinker --export-dynamic` to the linker driver's command line. I'll have a fix for it soon.
Comment #5 by dlang-bot — 2019-09-26T05:03:40Z
@JinShil created dlang/dmd pull request #10438 "Fix Issue 20244 - New dmd option -preview=noXlinker does not work on Linux to build a simple D application" fixing this issue: - Fix Issue 20244 - New dmd option -preview=noXlinker does not work on Linux to build a simple D application https://github.com/dlang/dmd/pull/10438
Comment #6 by Alan.W.Irwin1234 — 2019-09-26T05:38:23Z
Hi Mike: You had me going for a while and my comments on that collided with yours so I abandoned mine, and I am just glad you were finally able to replicate the bug!
Comment #7 by Alan.W.Irwin1234 — 2019-09-26T05:57:47Z
Hi Mike: You had me going for a while. My comments on that collided with yours so I abandoned mine, and I am just glad you were finally able to replicate the bug (duplicate bad flag) I find now for the same configuration file that you are using. Also, for me the same ("flag flag" instead of "-Xlinker flag") bug appears for me if I specify -L-Xlinker -L-flag on the command line. Finally, I notice JinShil has a one-line fix which I am about to test.
Comment #8 by dlang-bot — 2019-09-26T06:01:49Z
dlang/dmd pull request #10438 "Fix Issue 20244 - New dmd option -preview=noXlinker does not work on Linux to build a simple D application" was merged into master: - 838c1e3e3a4b0cf7b27c141ad8a5c68a992b6bcc by Mike: Fix Issue 20244 - New dmd option -preview=noXlinker does not work on Linux to build a simple D application https://github.com/dlang/dmd/pull/10438
Comment #9 by Alan.W.Irwin1234 — 2019-09-26T06:44:26Z
I just confirmed that git master branch HEAD fixes the bug that occurred for the case when dmd.conf was fixed like you suggested. Thanks for the help!