Comment #0 by burton-radons — 2010-07-31T09:38:19Z
This code fails to link:
import std.math;
void main() {
real function(real) c = &sin;
}
With the error message:
D:\Source>dmd-1 test.d test.exe
OPTLINK (R) for Win32 Release 8.00.2
Copyright (C) Digital Mars 1989-2009 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test)
Error 42: Symbol Undefined _D3std4math3sinFeZe
--- errorlevel 1
Because std.math.sin is intrinsic. This should either be detected at compile time or (better yet) a function should be added to Phobos that gives this function a body.
This affects treating large sets of functions homogenously, such as exporting to a scripting language.
Comment #1 by clugdbug — 2010-09-20T08:44:31Z
*** Issue 4696 has been marked as a duplicate of this issue. ***
Comment #2 by yebblies — 2011-09-19T07:23:21Z
*** Issue 6692 has been marked as a duplicate of this issue. ***
Comment #3 by andrej.mitrovich — 2013-02-15T14:49:10Z
Perhaps a possible workaround is to have the compiler emit a wrapper function when the address of an intrinsic is asked for, and return the pointer to the wrapper?
Comment #6 by mathias.lang — 2016-06-17T10:45:55Z
intrinsic have been moved to `core.math` and `std.math` nowadays (since 2.069 / https://github.com/dlang/phobos/pull/3599 ) provide wrappers around it to mitigate the issue.
In order to reproduce this, one can use:
import core.math;
void main() {
real function(real) c = &sin;
}
instead of the op's code.
Comment #7 by mathias.lang — 2016-06-17T10:47:49Z
*** Issue 5305 has been marked as a duplicate of this issue. ***
Comment #8 by razvan.nitu1305 — 2017-07-12T11:45:41Z
I think that this issue is no longer valid since using the std.math wrappers results in successful compilation. Even though using core.math results in link failure, I do not think this is a problem since that is the runtime library and who uses it should know that the functions declared there are intrinsics. Anyway, this is not a phobos bug anymore and I don't think it is a druntime one either. Closing
as fixed.
Comment #9 by mathias.lang — 2017-07-12T14:16:22Z
I strongly disagree with closing this bug.
> Even though using core.math results in link failure, I do not think this is a problem since that is the runtime library and who uses it should know that the functions declared there are intrinsics.
Relying on user knowing of internal details is not a solution. Moreover, this doesn't take into account generic code. If one write a template that accept a static function via a template this argument, do you really expect this person to handle the case of someone passing an intrinsic explicitly ?
Intrinsics shouldn't differ from regular functions.
> Anyway, this is not a phobos bug anymore and I don't think it is a druntime one either. Closing as fixed.
The correct course of action would be to properly tag the bug as being within DMD.
Comment #10 by bugzilla — 2017-10-25T03:07:57Z
It works fine when I try it with the latest.
Comment #11 by mathias.lang — 2017-10-25T12:47:31Z
@Walter: Did you read the comments ?
The test case nowadays is:
```
import core.math;
void main() {
real function(real) c = &sin;
}
```
And it still fails:
```
test.o: In function `_Dmain':
test.d:(.text._Dmain[_Dmain]+0x7): undefined reference to `_D4core4math3sinFNaNbNiNfeZe'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
```
Tested with both 2.076.1 and HEAD (51bc2fb42)
Comment #12 by dlang-bot — 2023-10-16T06:54:39Z
@SixthDot created dlang/dmd pull request #15699 "fix issue 4541 - linker failure due to AddrExp on intrinsic function" fixing this issue:
- fix issue 4541 - linker failure due to AddrExp on intrinsic function
The expression results now in a semantic-time error,
which is the only simple solution.
DMD Intrinsics map to libc functions, which can give the impression
that taking the address is possible, but more generally an intrinsic
can also have for effect to insert platform-specific instructions,
as seen in LLVM.
https://github.com/dlang/dmd/pull/15699
Comment #13 by robert.schadek — 2024-12-13T17:52:42Z