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
Here is the preprocessed code: # 194 "/usr/include/bits/stdio2.h" 3 4 extern # 194 "/usr/include/bits/stdio2.h" inline # 194 "/usr/include/bits/stdio2.h" 3 4 __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__access__ (__write_only__, 1, 2))) char * fgets (char * __s, int __n, FILE * __stream) { size_t sz = __builtin_object_size (__s, 1 > 1); if (((__builtin_constant_p (sz) && (sz) == (long unsigned int) -1) || (((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((long unsigned int) (__n)) <= ((sz)) / ((sizeof (char))))) && (((long unsigned int) (__n)) <= ((sz)) / ((sizeof (char))))))) return __fgets_alias (__s, __n, __stream); if ((((__typeof (__n)) 0 < (__typeof (__n)) -1 || (__builtin_constant_p (__n) && (__n) > 0)) && __builtin_constant_p ((((long unsigned int) (__n)) <= (sz) / (sizeof (char)))) && !(((long unsigned int) (__n)) <= (sz) / (sizeof (char))))) return __fgets_chk_warn (__s, sz, __n, __stream); return __fgets_chk (__s, sz, __n, __stream); }
Comment #4 by dlang-bugzilla — 2023-12-24T09:52:01Z
Reduced: #include <stdio.h> int foo() { int __n; return ((__typeof (__n)) 0 ); } Maybe just needs a #define __typeof typeof?
Comment #5 by dlang-bot — 2023-12-27T20:10:37Z
@WalterBright created dlang/dmd pull request #15957 "fix Issue 24297 - ImportC incompatible with glibc _FORTIFY_SOURCE" fixing this issue: - fix Issue 24297 - ImportC incompatible with glibc _FORTIFY_SOURCE https://github.com/dlang/dmd/pull/15957
Comment #6 by dlang-bot — 2023-12-27T21:22:57Z
dlang/dmd pull request #15957 "fix Issue 24297 - ImportC incompatible with glibc _FORTIFY_SOURCE" was merged into master: - 7ce929a02cd315abd8f0e420327625164a9c0c97 by Walter Bright: fix Issue 24297 - ImportC incompatible with glibc _FORTIFY_SOURCE https://github.com/dlang/dmd/pull/15957