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).
Makefile | 2 +-
libc/stdio/sscanf.c | 19 +++++++++++++++++++
libc/stdio/vsscanf.c | 4 ++++
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 libc/stdio/sscanf.c
diff --git a/Makefile b/Makefile
index 2ef75600..030416a8 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/libc/stdio/sscanf.c b/libc/stdio/sscanf.c
new file mode 100644
index 00000000..d7c02a6e
--- /dev/null
+++ b/libc/stdio/sscanf.c
@@ -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
diff --git a/libc/stdio/vsscanf.c b/libc/stdio/vsscanf.c
index 26f56fa8..0f301139 100644
--- a/libc/stdio/vsscanf.c
+++ b/libc/stdio/vsscanf.c
@@ -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
--
2.21.0