Fedora enabled -Werror=format-security which broke building sharutils because sharutils sources come with pregenerated libopts code <http://thread.gmane.org/gmane.comp.gnu.utils.bugs/18126>, bug #1037323. I fixed the issue by patching the generated header this way: --- a/src/shar-opts.h +++ b/src/shar-opts.h @@ -373,6 +373,7 @@ extern tOptions sharOptions; # include <libintl.h> # endif +static inline char* aoGetsText(char const* pz) __attribute__ ((format_arg(1))); static inline char* aoGetsText(char const* pz) { if (pz == NULL) return NULL; return (char*)gettext(pz); This is in line with gettext(3) which is marked the same way. Now I decided to unbundle the libopts because patching messages printed by libopts is a nightmare (bug #1074912). Thus I need to fix autogen. I can see in the autogen sources: petr@dhcp-0-146:~/fedora/autogen/autogen-5.18.2 $ grep -Hnr aoGetsText autoopts/genshell.h:170:static inline char* aoGetsText(char const* pz) { autoopts/genshell.h:174:# define _(s) aoGetsText(s) autoopts/tpl/opthead.tlib:668:static inline char* aoGetsText(char const* pz) { autoopts/tpl/opthead.tlib:672:# define _(s) aoGetsText(s) So I guess you one of the locations has be patched. If you are not interested in this issue, I can develop the fix the commit it into Fedora.
CCing upstream maintainer.
"genshell.h" is a derived file that you are not using. Obviously, I cannot just put the __attribute__ string into the template file. I have to do something like: #ifndef ATTRIBUTE #define ATTRIBUTE(_a) #endif static inline char* aoGetsText(char const* pz) ATTRIBUTE((format_arg(1))) { but I do not know the conventional spelling of the attribute wrapper macro.
See GCC texinfo page (info gcc 'C Extensions' 'Attribute Syntax').
Doing it for GCC is not the issue. The problem is that the generated code needs to be compilable with other compilers that may not be using GCC's conventions. Therefore, it must be macro-wrapped in some way. e.g. #ifdef __GNUC__ #define ATTRIBUTE(_a) __attribute__(_a) #else #define ATTRIBUTE(_a) #endif So my question to you is, "How would you like that wrapped?" I will not emit all of that in the code. I am willing to emit the "#ifndef" variation in comment #2. How would you like the attribute wrapper spelled? Thanks!
How about GNUC_ATTRIBUTE?
After some googling, it seems to me the convention is to define __attribute__() as a macro expanding to nothing with non-gcc compilers.
The new template will now produce the following code: # ifndef __attribute__ # define __attribute__(_a) # endif static inline char* aoGetsText(char const* pz) __attribute__ ((format_arg(1))); static inline char* aoGetsText(char const* pz) { if (pz == NULL) return NULL; return (char*)gettext(pz); }
P.S. "Thank you!" :)
PPS: http://autogen.sourceforge.net/data/autogen-5.18.3pre18.tar.xz
(In reply to Bruce Korb from comment #7) > The new template will now produce the following code: > > # ifndef __attribute__ > # define __attribute__(_a) > # endif Hm, so the applications are now expected to define __attribute__ with gcc?
Your original suggestion of just using __attribute__ would have required defining it for all compilers other than GNU. The _Noreturn attribute I can get from gnulib. The format attribute is not available via gnulib. Probably the best thing is an autoconf feature test that yields some wrapper macro. Unfortunately, this is just a play time activity and I am neck deep in a start up. Play time is limited. Please make a suggestion soon because I hope to make a release this weekend. Thank you for your help! Regards, Bruce
What about? #if !defined(__GNUC__) #define __attribute__(a) #endif static inline char* aoGetsText(char const* pz) __attribute__ ((format_arg(1))); I could track format_arg support to GCC 2.95.3. So I guess there is no need to constrain the definition with a specific GCC version.
I got a short break. The wrapper macro will be named ATTRIBUTE_FORMAT_ARG(_a): > AC_DEFUN([AG_COMPILE_FORMAT_ARG],[ > AC_MSG_CHECKING([whether __attribute__((format_arg(n))) works]) > AC_CACHE_VAL([ag_cv_compile_format_arg],[ > AC_COMPILE_IFELSE( > AC_LANG_PROGRAM([@%:@include <stdio.h> > char const * foo(char const * fmt, int v) > __attribute__((format_arg(1)));], > [printf( foo("argc is %d\n", argc), argc);]), > [ag_cv_compile_format_arg=yes], > [ag_cv_compile_format_arg=no] > ) # end of AC_COMPILE_IFELSE > ]) # end of AC_CACHE_VAL for ag_cv_compile_format_arg > AC_MSG_RESULT([${ag_cv_compile_format_arg}]) > if test "X${ag_cv_compile_format_arg}" != Xno > then > format_arg_expansion="__attribute__((format_arg(_a)))" > else > format_arg_expansion="" > fi > AC_DEFINE_UNQUOTED([ATTRIBUTE_FORMAT_ARG(_a)], > [${format_arg_expansion}], > [format_arg attribute wrapper]) > ]) # end of AC_DEFUN of AG_COMPILE_FORMAT_ARG
autogen has been updated to 5.18.4. To fix the format warnings the applications need to define the ATTRIBUTE_FORMAT_ARG macro, it's not defined automatically. FWIW, the AG_COMPILE_FORMAT_ARG test code doesn't seem to work correctly here as main is declared without argc.