-ffreestanding option

Iain Buclaw ibuclaw at gdcproject.org
Thu Jul 26 19:57:14 UTC 2018


On 25 July 2018 at 12:05, Mike Franklin via D.gnu <d.gnu at puremagic.com> wrote:
> On Wednesday, 25 July 2018 at 08:37:28 UTC, Zheng (Vic) Luo wrote:
>
>> Current implementation of compilers assumes the existence of some symbols
>> from libc, which leads to an infinite loop if we want to implement
>> primitives like "memset" with our own code because the compiler will
>> optimize consecutive set with "memset". This suggests that we cannot write a
>> freestanding program without supports from compiler. With "-betterC" flag,
>> dmd/gdc/ldc also come into this issue[5], which also applies to C/C++[1] and
>> rust [2][3][4].
>
>
> GDC doesn't seem to be affected.  See https://explore.dgnu.org/g/ZJVjAu
> i.e. no recursive calls to `memset`, but I don't know if I just got lucky
> with my implementation.
>
>> It would be better to provide a standard flag like "-ffreestanding" (or
>> -fno-builtin?) to disable such optimizations to facilitate freestanding
>> programming instead of forcing the developers to hack around different
>> compiler implementations, so I was wondering is there any progress on this
>> problem?
>
>
> According to https://wiki.dlang.org/Using_GDC, `-fno-builtin` is already
> there.
>

It only goes as far as not recognizing user declared functions as
being built-in.  The compiler may still generate builtin calls
internally, and you may explicitly call any function in the
gcc.builtins module.

Iain.


More information about the D.gnu mailing list