Skip to content

Commit

Permalink
libc: avoid weak_alias() warnings from gcc 9.
Browse files Browse the repository at this point in the history
gcc 9 started to warn about alias created with different "attributes"
(__attribute__(...)) from the source symbol. Unfortunately, in a couple
of cases gcc also started to add a gratuituous "nothrow" attribute to
our C code (which can never throw in any case...) and as a result,
weak_alias throws.

I tried to fix this in a number of ways, but none of them worked
satisfactorily. This patch does something ugly, that works - add
the nothrow attribute manually in the two places which had this
problem. Unfortunately it means we edited yet another Musl source
file (stdio/sscanf.c).

Signed-off-by: Nadav Har'El <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
nyh authored and Waldemar Kozaczuk committed May 19, 2019
1 parent 27cf878 commit 51722a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ musl += stdio/setlinebuf.o
musl += stdio/setvbuf.o
musl += stdio/snprintf.o
musl += stdio/sprintf.o
musl += stdio/sscanf.o
libc += stdio/sscanf.o
libc += stdio/stderr.o
libc += stdio/stdin.o
libc += stdio/stdout.o
Expand Down
19 changes: 19 additions & 0 deletions libc/stdio/sscanf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdarg.h>
#include "libc.h"

int sscanf(const char *restrict s, const char *restrict fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsscanf(s, fmt, ap);
va_end(ap);
return ret;
}

#if __GNUC__ >= 9
weak_alias(sscanf,__isoc99_sscanf) __attribute__((nothrow));
#else
weak_alias(sscanf,__isoc99_sscanf);
#endif
4 changes: 4 additions & 0 deletions libc/stdio/vsscanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap)
return vfscanf(&f, fmt, ap);
}

#if __GNUC__ >= 9
weak_alias(vsscanf,__isoc99_vsscanf) __attribute__((nothrow));
#else
weak_alias(vsscanf,__isoc99_vsscanf);
#endif

0 comments on commit 51722a9

Please sign in to comment.