www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Statics, FreeBSD

reply Don Allen <donaldcallen gmail.com> writes:
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 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 giovanni:/tmp$ ls -l testit
ls: testit: No such file or directory
(dmd-2.107.1)dca giovanni:/tmp$ ldc2 testit.d
(dmd-2.107.1)dca giovanni:/tmp$ testit
1
(dmd-2.107.1)dca 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.
Apr 06
parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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 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 giovanni:/tmp$ ls -l testit
 ls: testit: No such file or directory
 (dmd-2.107.1)dca giovanni:/tmp$ ldc2 testit.d
 (dmd-2.107.1)dca giovanni:/tmp$ testit
 1
 (dmd-2.107.1)dca 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
Apr 06
parent reply Don Allen <donaldcallen gmail.com> writes:
On Sunday, 7 April 2024 at 04:58:29 UTC, Jonathan M Davis wrote:
 On Saturday, April 6, 2024 6:35:13 AM MDT Don Allen via 
 Digitalmars-d wrote:
[snip]
 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
I said I was hoping for a useful comment and I got one. Adding -fPIC to DFLAGS in dmd.conf does indeed fix the problem. Thank you! I haven't filed a bug report yet, but will, so it makes it onto someone's todo list.
Apr 07
parent Don Allen <donaldcallen gmail.com> writes:
On Sunday, 7 April 2024 at 13:08:23 UTC, Don Allen wrote:
 On Sunday, 7 April 2024 at 04:58:29 UTC, Jonathan M Davis wrote:
 I haven't filed a bug report yet, but will, so it makes it onto 
 someone's todo list.
Pull request created.
Apr 07