gettext: Fix overloadable error with clang
PATCH 1/1 gettext: Fix overloadable error with clang
Clang detects that getcwd is being re-declared and signatures don't match, simple solution is to let clang use overloadable attribute
--- .../gettext/gettext-0.20.1/overloadable.patch | 22 +++++++++++++++++++ meta/recipes-core/gettext/gettext_0.20.1.bb | 1 + 2 files changed, 23 insertions(+) create mode 100644 meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch
meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch new file +22 -0
@@ -0,0 +1,22 @@ +Use overloadable attribute to aid clang + +Fixes +dcigettext.c:147:7: error: redeclaration of 'getcwd' must have the 'overloadable' attribute + +Upstream-Status: Pending +Signed-off-by: Khem Raj <[email protected]> +--- a/gettext-runtime/intl/dcigettext.c ++++ b/gettext-runtime/intl/dcigettext.c +@@ -144,7 +144,11 @@ char *getwd (); + # if VMS + # define getcwd(buf, max) (getcwd) (buf, max, 0) + # else +-char *getcwd (); ++char ++#ifdef __clang__ ++__attribute__((overloadable)) ++#endif ++*getcwd (); + # endif + # endif + # ifndef HAVE_STPCPY
meta/recipes-core/gettext/gettext_0.20.1.bb +1 -0
@@ -25,6 +25,7 @@ SRC_URI = "${GNU_MIRROR}/gettext/gettext-${PV}.tar.gz \ file://serial-tests-config.patch \ file://0001-msgmerge-Fix-behaviour-of-for-msgfmt-on-PO-files-wit.patch \ file://0001-tests-autopoint-3-unset-MAKEFLAGS.patch \ + file://overloadable.patch \ " SRC_URI[md5sum] = "bb5b0c0caa028105f3ca1905ddc306e2"
Signature · 1 line
2.25.0
meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch line 14
Quoted 8 lines · Khem Raj
Clang detects that getcwd is being re-declared and signatures don't match, simple solution is to let clang use overloadable attribute
...meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch new file +3
-0+Fixes +dcigettext.c:147:7: error: redeclaration of 'getcwd' must have the 'overloadable' attribute +-char *getcwd ();
Looks like a bug in clang to me, and should be fixed there.
The code does not tell anything regarding the parameters, but clang seems to misinterpret it as "no parameters".
cu
Adrian
Quoted 13 lines · Adrian Bunk
meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch line 14
Quoted 8 lines · Khem Raj
Clang detects that getcwd is being re-declared and signatures don't match, simple solution is to let clang use overloadable attribute
...meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch new file +3
-0+Fixes +dcigettext.c:147:7: error: redeclaration of 'getcwd' must have the 'overloadable' attribute +-char *getcwd ();Looks like a bug in clang to me, and should be fixed there.
Quoted 3 lines
The code does not tell anything regarding the parameters, but clang seems to misinterpret it as "no parameters".
its conflicting with declaration from glibc system headers
usr/include/unistd.h:extern char *getcwd (char *__buf, size_t __size) __THROW __wur;
Quoted 2 lines
cu
Adrian
Quoted 14 lines · Khem Raj
Quoted 13 lines · Adrian Bunk
meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch line 14
Quoted 8 lines · Khem Raj
Clang detects that getcwd is being re-declared and signatures don't match, simple solution is to let clang use overloadable attribute
...meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch new file +3
-0+Fixes +dcigettext.c:147:7: error: redeclaration of 'getcwd' must have the 'overloadable' attribute +-char *getcwd ();Looks like a bug in clang to me, and should be fixed there.
Quoted 5 lines
Quoted 3 lines
The code does not tell anything regarding the parameters, but clang seems to misinterpret it as "no parameters".
its conflicting with declaration from glibc system headers
...
Why did the glibc 2.31 upgrade add a not upstreamed patch from 2017 that created these conflicts?
The commit message does not mention that this patch was added, and an OE-only patch that makes a compiler reject valid C code is not good.
cu
Adrian
Quoted 16 lines · Adrian Bunk
Quoted 14 lines · Khem Raj
Quoted 13 lines · Adrian Bunk
meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch line 14
Quoted 8 lines · Khem Raj
Clang detects that getcwd is being re-declared and signatures don't match, simple solution is to let clang use overloadable attribute
...meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch new file +3
-0+Fixes +dcigettext.c:147:7: error: redeclaration of 'getcwd' must have the 'overloadable' attribute +-char *getcwd ();Looks like a bug in clang to me, and should be fixed there.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
The code does not tell anything regarding the parameters, but clang seems to misinterpret it as "no parameters".
its conflicting with declaration from glibc system headers
...Why did the glibc 2.31 upgrade add a not upstreamed patch from 2017 that created these conflicts?
This supports building userspace with clang better and find more errors when fortify sources option is on.
this patch was already proposed to glibc and I will follow up on it. It definitely improves fortify when using clang
Quoted 4 lines
The commit message does not mention that this patch was added, and an OE-only patch that makes a compiler reject valid C code is not good.
I think thats my bad as it slipped my mind with numerous rebases I did over the life of the glibc patchset.
however, I think its probably best to leave it outside core for now. There is another patchset I will do for
glibc 2.31 where I will drop it and perhaps house it in meta-clang.
Quoted 2 lines
cu
Adrian
Quoted 20 lines · Khem Raj
Quoted 19 lines · Adrian Bunk
Quoted 17 lines · Khem Raj
Quoted 16 lines · Adrian Bunk
meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch line 14
Quoted 8 lines · Khem Raj
Clang detects that getcwd is being re-declared and signatures don't match, simple solution is to let clang use overloadable attribute
...meta/recipes-core/gettext/gettext-0.20.1/overloadable.patch new file +3
-0+Fixes +dcigettext.c:147:7: error: redeclaration of 'getcwd' must have the 'overloadable' attribute +-char *getcwd ();Looks like a bug in clang to me, and should be fixed there.
The code does not tell anything regarding the parameters, but clang seems to misinterpret it as "no parameters".
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
its conflicting with declaration from glibc system headers
...Why did the glibc 2.31 upgrade add a not upstreamed patch from 2017 that created these conflicts?
This supports building userspace with clang better and find more errors when fortify sources option is on.
What "errors" are you referring to?
From a semantic point of view the code is correct.
This is a relict from K&R C that novice C programmers often misinterpret, but I'd say gcc made the right call by not including the warning for the more general case in -Wall.
The cases with an actual problem are being caught by a different gcc warning that has been included in -Wall for decades.
Quoted 1 line
this patch was already proposed to glibc and I will follow up on it.
This is an area with different semantics in C and C++.
All your "fixes" indicate that the result is C++ semantics in C code. Which is not something you can do in the public glibc headers.
Quoted 1 line
It definitely improves fortify when using clang
What is the point of all this when you "fix" the bogus error caused by this patch with a function attribute like in this case for gettext?
The gettext patch is simply wrong.
Quoted 7 lines
Quoted 3 lines
The commit message does not mention that this patch was added, and an OE-only patch that makes a compiler reject valid C code is not good.
I think thats my bad as it slipped my mind with numerous rebases I did over the life of the glibc patchset.
...
Was the glibc upgrade sent to the mailing list for review?
cu
Adrian