Bug 24297 – ImportC incompatible with glibc _FORTIFY_SOURCE
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P5
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2023-12-22T11:10:18Z
Last change time
2023-12-27T21:22:57Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2023-12-22T11:10:18Z
$ echo '#include <stdio.h>' > test.c && dmd -P=-D_FORTIFY_SOURCE -P=-O test.c
/usr/include/bits/stdio2.h(198): Error: found `0` when expecting `)`
/usr/include/bits/stdio2.h(198): Error: found `)` instead of statement
/usr/include/bits/stdio2.h(200): Error: found `0` when expecting `)`
/usr/include/bits/stdio2.h(200): Error: found `)` instead of statement
/usr/include/bits/stdio2.h(210): Error: found `0` when expecting `)`
/usr/include/bits/stdio2.h(210): Error: found `)` instead of statement
/usr/include/bits/stdio2.h(212): Error: found `0` when expecting `)`
/usr/include/bits/stdio2.h(212): Error: found `)` instead of statement
/usr/include/bits/stdio2.h(237): Error: found `0` when expecting `)`
/usr/include/bits/stdio2.h(237): Error: found `)` instead of statement
/usr/include/bits/stdio2.h(260): Error: no type for declarator before `return`
/usr/include/bits/stdio2.h(261): Error: no type for declarator before `}`
/usr/include/bits/stdio2.h(262): Error: no type for declarator before `if`
/usr/include/bits/stdio2.h(264): Error: no type for declarator before `return`
/usr/include/bits/stdio2.h(266): Error: no type for declarator before `}`
Relevant part of the file:
194 __fortify_function __wur __fortified_attr_access (__write_only__, 1, 2) char *
195 fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
196 {
197 size_t sz = __glibc_objsize (__s);
198 if (__glibc_safe_or_unknown_len (__n, sizeof (char), sz))
199 return __fgets_alias (__s, __n, __stream);
200 if (__glibc_unsafe_len (__n, sizeof (char), sz))
201 return __fgets_chk_warn (__s, sz, __n, __stream);
202 return __fgets_chk (__s, sz, __n, __stream);
203 }
Nix enables these flags automatically for its wrapped C preprocessor. It is enabled by default but can be disabled.
Not sure if this is something that's at all reasonable to implement in ImportC or not.
Comment #1 by bugzilla — 2023-12-24T06:36:34Z
The usual way to handle these sorts of extensions is to make macros for them that expand to nothing, and put those macros in druntime/src/importc.h.
However, this bug report has insufficient information in it to do that, though I suspect that an:
#undef _FORTIFY_SOURCE
might work?
Comment #2 by dlang-bugzilla — 2023-12-24T09:44:09Z
> However, this bug report has insufficient information in it to do that
Why do you say that? This problem should be reproducible on any GNU/Linux machine without additional setup.
What information is missing?
> though I suspect that an:
>
> #undef _FORTIFY_SOURCE
>
> might work?
Ah, certainly, that works! Not worth fixing whatever things get expanded to?
Comment #3 by dlang-bugzilla — 2023-12-24T09:45:33Z