Can't implement conformant memset/memcpy without compiler -ffreestanding support
Zheng Luo (Vic)
vicluo96 at gmail.com
Wed Jul 25 08:57:41 UTC 2018
Current implementation of compilers assumes libc implementation,
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, ldc also comes into this issue,
which also applies to C/C++[1] and rust [2][3][4].
gcc and clang provides an option "-ffreestanding" to bypass
optimizations that need libc support. Although we can hack around
this issue by making our implementation complicated enough/using
assembly to bypass the optimizer, it would be better to provide a
standard flag like "-ffreestanding" for all compilers to disable
such optimizations, so that developers won't have to hack around
different compiler implementations.
[1] https://godbolt.org/g/5gVWeN
[2]
https://play.rust-lang.org/?gist=64f2acafa8cec112893633a5f2e12a9a&version=stable&mode=release&edition=2015
[3] https://github.com/rust-lang/rust/issues/10116
[4] https://github.com/thestinger/rust-core#freestanding
More information about the Digitalmars-d
mailing list