32-bit DMD compiled programs prints "segmentation fault"

Suleyman sahmi.soulaimane at gmail.com
Sun Nov 3 21:05:50 UTC 2019

On Sunday, 3 November 2019 at 04:36:50 UTC, Walter Bright wrote:
> On 11/2/2019 10:06 AM, Suleyman wrote:
>> On Saturday, 2 November 2019 at 00:04:27 UTC, Walter Bright 
>> wrote:
>>> Why does the PIE code gen work fine on Linux but not Debian?
>>> (It passes all the 32 bit tests on the autotester.)
>> GCC 6 enabled PIE by default, you have to disable it manually 
>> with `-no-pie`. The auto-tester uses and ancient GCC version 
>> which is not affected.
> Yes, but I'd like to know exactly what code sequence generated 
> by dmd is not working, vs what ldc is generating that does work.

There is nothing wrong with DMD, the problem is in the 
coordination with the linker.
For example:

void printf(const char*, ...);

int g = 10;

void main()
     int i = g;      // crash
     printf("%d\n", i);
Note: compile the program with -betterC to avoid linking druntime.

This program crashes, but if you add the -fPIC switch it works.

LDC has -fPIC by default.

More information about the Digitalmars-d mailing list