[PATCH 1/4] tracepoints: fix for compiling on gcc 9

7 views
Skip to first unread message

Nadav Har'El

unread,
May 19, 2019, 8:26:33 AM5/19/19
to osv...@googlegroups.com, Nadav Har'El
In gcc 9.1.1, strictly following the C++ standard, one is no longer
allowed to specify attributes, e.g., [[gnu::cold]], on function
definitions - only on function declaration. As an annoying side-effect,
we get warnings if we specify them on a lambda, which is both a declaration
and a definition.

The easiest workaround is to use the old-style __attribute__((cold))
instead of the more modern syntax [[gnu::cold]]. The old-style syntax
isn't bound by the C++ standard, and its behavior hasn't changed in
gcc 9.1.1.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
---
arch/x64/arch-trace.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x64/arch-trace.hh b/arch/x64/arch-trace.hh
index 55ddf822..908ee9ac 100644
--- a/arch/x64/arch-trace.hh
+++ b/arch/x64/arch-trace.hh
@@ -34,7 +34,7 @@ slow_path:
auto pdata = &data;
// encapsulate the trace_slow_path() in a function callable from asm:
void (*do_slow_path)(tracepointv* tp, decltype(data)* d)
- = [](tracepointv* tp, decltype(data)* d) [[gnu::cold]] {
+ = [](tracepointv* tp, decltype(data)* d) __attribute__((cold)) {
tp->trace_slow_path(*d);
};
tracepointv* tp = this;
--
2.21.0

Nadav Har'El

unread,
May 19, 2019, 8:26:36 AM5/19/19
to osv...@googlegroups.com, Nadav Har'El
gcc 9.1.1 warns about strncpy() which can lead to a missing null at the
end of the destination. Let's use strlcpy(), which doesn't have this
problem.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
---
include/osv/sched.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/osv/sched.hh b/include/osv/sched.hh
index 033dfaed..5e0caedf 100644
--- a/include/osv/sched.hh
+++ b/include/osv/sched.hh
@@ -359,7 +359,7 @@ public:
return *this;
}
attr& name(std::string n) {
- strncpy(_name.data(), n.data(), sizeof(_name) - 1);
+ strlcpy(_name.data(), n.data(), sizeof(_name));
return *this;
}
};
--
2.21.0

Nadav Har'El

unread,
May 19, 2019, 8:26:37 AM5/19/19
to osv...@googlegroups.com, Nadav Har'El
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 <n...@scylladb.com>
---
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

Nadav Har'El

unread,
May 19, 2019, 8:26:38 AM5/19/19
to osv...@googlegroups.com, Nadav Har'El
gcc 9 started to give us the following warnings:

external/x64/acpica/source/components/tables/tbfind.c:162:5: error: ‘strncpy’ specified bound 6 equals destination size [-Werror=stringop-truncation]
162 | ACPI_STRNCPY (Header.OemId, OemId, ACPI_OEM_ID_SIZE);
| ^~~~~~~~~~~~

Let's just turn of this warning for the ACPI files. We're not going
to fix problems in that library (and I'm not even sure it is a real
problem, I don't know if "OemId" is really guaranteed to be null
terminated).

Signed-off-by: Nadav Har'El <n...@scylladb.com>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 030416a8..a274cd19 100644
--- a/Makefile
+++ b/Makefile
@@ -473,7 +473,7 @@ acpi-defines = -DACPI_MACHINE_WIDTH=64 -DACPI_USE_LOCAL_CACHE
acpi-source := $(shell find external/$(arch)/acpica/source/components -type f -name '*.c')
acpi = $(patsubst %.c, %.o, $(acpi-source))

-$(acpi:%=$(out)/%): CFLAGS += -fno-strict-aliasing
+$(acpi:%=$(out)/%): CFLAGS += -fno-strict-aliasing -Wno-stringop-truncation

endif # x64

--
2.21.0

Commit Bot

unread,
May 19, 2019, 3:39:32 PM5/19/19
to osv...@googlegroups.com, Nadav Har'El
From: Nadav Har'El <n...@scylladb.com>
Committer: Waldemar Kozaczuk <wkoz...@WALDEMARs-Air.attlocal.net>
Branch: master

tracepoints: fix for compiling on gcc 9

In gcc 9.1.1, strictly following the C++ standard, one is no longer
allowed to specify attributes, e.g., [[gnu::cold]], on function
definitions - only on function declaration. As an annoying side-effect,
we get warnings if we specify them on a lambda, which is both a declaration
and a definition.

The easiest workaround is to use the old-style __attribute__((cold))
instead of the more modern syntax [[gnu::cold]]. The old-style syntax
isn't bound by the C++ standard, and its behavior hasn't changed in
gcc 9.1.1.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <201905191226...@scylladb.com>

---
diff --git a/arch/x64/arch-trace.hh b/arch/x64/arch-trace.hh

Commit Bot

unread,
May 19, 2019, 3:39:33 PM5/19/19
to osv...@googlegroups.com, Nadav Har'El
From: Nadav Har'El <n...@scylladb.com>
Committer: Waldemar Kozaczuk <wkoz...@WALDEMARs-Air.attlocal.net>
Branch: master

sched: fix gcc 9 warning

gcc 9.1.1 warns about strncpy() which can lead to a missing null at the
end of the destination. Let's use strlcpy(), which doesn't have this
problem.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <201905191226...@scylladb.com>

---
diff --git a/include/osv/sched.hh b/include/osv/sched.hh

Commit Bot

unread,
May 19, 2019, 3:39:35 PM5/19/19
to osv...@googlegroups.com, Nadav Har'El
From: Nadav Har'El <n...@scylladb.com>
Committer: Waldemar Kozaczuk <wkoz...@WALDEMARs-Air.attlocal.net>
Branch: master

libc: avoid weak_alias() warnings from gcc 9.

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 <n...@scylladb.com>
Message-Id: <201905191226...@scylladb.com>

---
diff --git a/Makefile b/Makefile
--- 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
--- a/libc/stdio/sscanf.c
+++ 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

Commit Bot

unread,
May 19, 2019, 3:39:36 PM5/19/19
to osv...@googlegroups.com, Nadav Har'El
From: Nadav Har'El <n...@scylladb.com>
Committer: Waldemar Kozaczuk <wkoz...@WALDEMARs-Air.attlocal.net>
Branch: master

acpi: ignore new gcc 9 warning

gcc 9 started to give us the following warnings:

external/x64/acpica/source/components/tables/tbfind.c:162:5: error:
‘strncpy’ specified bound 6 equals destination size
[-Werror=stringop-truncation]
162 | ACPI_STRNCPY (Header.OemId, OemId, ACPI_OEM_ID_SIZE);
| ^~~~~~~~~~~~

Let's just turn of this warning for the ACPI files. We're not going
to fix problems in that library (and I'm not even sure it is a real
problem, I don't know if "OemId" is really guaranteed to be null
terminated).

Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <201905191226...@scylladb.com>

---
diff --git a/Makefile b/Makefile
Reply all
Reply to author
Forward
0 new messages