Statics, FreeBSD

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Apr 7 04:58:29 UTC 2024


On Saturday, April 6, 2024 6:35:13 AM MDT Don Allen via Digitalmars-d wrote:
> I've had some issues (seg faults) with statics on FreeBSD 14
> recently in code that works on Linux and wrote this little test
> program to try to isolate them:
>
> ````
> import std.stdio;
>
> int main(string[] args)
> {
>      static int foo;
>      foo = 1;
>      writefln("%d", foo);
>      return 0;
> }
> ````
>
> Compiling with dmd produces some interesting complaints from the
> linker, whereas compiling with ldc (1.35) does not:
>
> ````
> (dmd-2.107.1)dca at giovanni:/tmp$ dmd testit.d
> ld: error: testit.o:(function D main: .text._Dmain+0xe):
> R_X86_64_GOTTPOFF must be used in MOVQ or ADDQ instructions only
> ld: error: testit.o:(function D main: .text._Dmain+0x26):
> R_X86_64_GOTTPOFF must be used in MOVQ or ADDQ instructions only
> cc: error: linker command failed with exit code 1 (use -v to see
> invocation)
> Error: linker exited with status 1
> (dmd-2.107.1)dca at giovanni:/tmp$ ls -l testit
> ls: testit: No such file or directory
> (dmd-2.107.1)dca at giovanni:/tmp$ ldc2 testit.d
> (dmd-2.107.1)dca at giovanni:/tmp$ testit
> 1
> (dmd-2.107.1)dca at giovanni:/tmp$
>
> ````
>
> I will file a bug report, but thought I'd post this here as well,
> to see if any of you had some useful observations about this.

It would appear that the problem is that the dmd.conf provided with dmd for
FreeBSD does not have -fPIC in DFLAGS.

My setup puts -fPIC in there, and it's been working just fine that way with
multiple versions of FreeBSD (since I haven't changed it recently),
including FreeBSD 14, and when I compare my dmd.conf with the one in the
download from dlang.org, other than path differences, that's the difference.

When I download dmd from dlang.org and put that on my path, your example
fails as described, whereas it works just fine with the dmd that I built
locally, and if I edit the dmd.conf that comes from dlang.org to include
-fPIC, the problem goes away. So, it looks like we probably need to fix it
so that the dmd.conf that's distributed with dmd for FreeBSD needs to have
-fPIC added to its DFLAGS.

- Jonathan M Davis





More information about the Digitalmars-d mailing list