Skip to contentSkip to conversation

tools: fix clang build

PATCH Superseded Wei Liu 4 participants 8 messages Jul 23, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover tools: fix clang build

See individual patch for details.

Wei Liu (2):
tools/gdbsx: fix build with clang 3.8
ocaml: remove undefined behaviour in systemd_stubs.c

 tools/debugger/gdbsx/Rules.mk         | 4 ++++
 tools/ocaml/xenstored/systemd_stubs.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#1 lore raw

PATCH 1/2 tools/gdbsx: fix build with clang 3.8

Currently building gdbsx with clang 3.8 gives the following errors:

xg_main.c:783:17: error: 'aligned' attribute ignored when parsing type [-Werror,-Wignored-attributes]

    iop->uva = (uint64_aligned_t)((unsigned long)tobuf);
                ^~~~~~~~~~~~~~~~
/builds/liuw/xen/tools/debugger/gdbsx/xg/../../../../tools/include/xen/arch-x86/xen-x86_32.h:105:50: note: expanded from macro 'uint64_aligned_t'
                                                 ^~~~~~~~~~
xg_main.c:816:17: error: 'aligned' attribute ignored when parsing type [-Werror,-Wignored-attributes]
    iop->uva = (uint64_aligned_t)((unsigned long)frombuf);
                ^~~~~~~~~~~~~~~~

/builds/liuw/xen/tools/debugger/gdbsx/xg/../../../../tools/include/xen/arch-x86/xen-x86_32.h:105:50: note: expanded from macro 'uint64_aligned_t'

According to https://bugs.llvm.org/show_bug.cgi?id=11071, this issue has been fixed in clang. But we're not going to get that in 3.8.

Explicitly disable that warning to fix the build.

---
Cc: Elena Ufimtseva <[email protected]>

See also:
https://patches.linaro.org/patch/27062/
https://gitlab.com/liuw/xen/-/jobs/83610026

---
 tools/debugger/gdbsx/Rules.mk | 4 ++++
 1 file changed, 4 insertions(+)
tools/debugger/gdbsx/Rules.mk +4 -0
index 6e38f2df99..dd9bd0b6cf 100644
@@ -2,3 +2,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 CFLAGS   += -Werror -Wmissing-prototypes 
 # (gcc 4.3x and later)   -Wconversion -Wno-sign-conversion
+
+ifeq ($(clang),y)
+CFLAGS += -Wno-ignored-attributes
+endif
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] tools/gdbsx: fix build with clang 3.8

Quoted 33 lines · Wei Liu

Currently building gdbsx with clang 3.8 gives the following errors:

xg_main.c:783:17: error: 'aligned' attribute ignored when parsing type [-Werror,-Wignored-attributes]

    iop->uva = (uint64_aligned_t)((unsigned long)tobuf);
                ^~~~~~~~~~~~~~~~
/builds/liuw/xen/tools/debugger/gdbsx/xg/../../../../tools/include/xen/arch-x86/xen-x86_32.h:105:50: note: expanded from macro 'uint64_aligned_t'
                                                 ^~~~~~~~~~
xg_main.c:816:17: error: 'aligned' attribute ignored when parsing type [-Werror,-Wignored-attributes]
    iop->uva = (uint64_aligned_t)((unsigned long)frombuf);
                ^~~~~~~~~~~~~~~~

/builds/liuw/xen/tools/debugger/gdbsx/xg/../../../../tools/include/xen/arch-x86/xen-x86_32.h:105:50: note: expanded from macro 'uint64_aligned_t'

According to https://bugs.llvm.org/show_bug.cgi?id=11071, this issue has been fixed in clang. But we're not going to get that in 3.8.

Explicitly disable that warning to fix the build.

---
Cc: Elena Ufimtseva <[email protected]>

See also:
https://patches.linaro.org/patch/27062/
https://gitlab.com/liuw/xen/-/jobs/83610026

---
 tools/debugger/gdbsx/Rules.mk | 4 ++++
 1 file changed, 4 insertions(+)
tools/debugger/gdbsx/Rules.mk +0 -0
index 6e38f2df99..dd9bd0b6cf 100644

tools/debugger/gdbsx/Rules.mk include $(XEN_ROOT)/tools/Rules.mk · line 8

Quoted 7 lines
tools/debugger/gdbsx/Rules.mk +4 -0
@@ -2,3 +2,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 CFLAGS   += -Werror -Wmissing-prototypes 
 # (gcc 4.3x and later)   -Wconversion -Wno-sign-conversion
+
+ifeq ($(clang),y)
+CFLAGS += -Wno-ignored-attributes
+endif

I would use

CFLAGS-$(clang) += ...

Because it's shorter.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#3 lore raw

PATCH 2/2 ocaml: remove undefined behaviour in systemd_stubs.c

In reply to Wei Liu

Clang complains:

systemd_stubs.c:51:8: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]

        ret = Val_int(-1U);
              ^~~~~~~~~~~~

Simply change the return value to 0.

---
Cc: Christian Lindig <[email protected]>
Cc: David Scott <[email protected]>

See: https://gitlab.com/liuw/xen/-/jobs/83628833

---
 tools/ocaml/xenstored/systemd_stubs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ocaml/xenstored/systemd_stubs.c +1 -1
index 490156c06a..d1dd33c95b 100644
@@ -48,7 +48,7 @@ CAMLprim value ocaml_sd_notify_ready(value ignore)
 	CAMLparam1(ignore);
 	CAMLlocal1(ret);
 
-	ret = Val_int(-1U);
+	ret = Val_int(0);
 
 	CAMLreturn(ret);
 }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Re: [PATCH 2/2] ocaml: remove undefined behaviour in systemd_stubs.c

Quoted 7 lines · Wei Liu

Clang complains:

systemd_stubs.c:51:8: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]

        ret = Val_int(-1U);
              ^~~~~~~~~~~~

Simply change the return value to 0.

That will break the function though, as it previously returned -1.

Unfortunately, the breakage here is inside Val_int(), which is defined thusly:

typedef long intnat;

#define Val_long(x)     (((intnat)(x) << 1) + 1)
#define Long_val(x)     ((x) >> 1)
#define Val_int(x) Val_long(x)
#define Int_val(x) ((int) Long_val(x))

I can't see any way of making Val_int() work for negative integers.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#5 lore raw

Re: [PATCH 2/2] ocaml: remove undefined behaviour in systemd_stubs.c

Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Wei Liu

Clang complains:

systemd_stubs.c:51:8: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]

        ret = Val_int(-1U);
              ^~~~~~~~~~~~

Simply change the return value to 0.

That will break the function though, as it previously returned -1.

I don't think the caller cares about the return value. The function signature is unit -> unit for sd_nofity_ready, and the return value is not checked at all. I admit I could have misread the code though.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Re: [PATCH 2/2] ocaml: remove undefined behaviour in systemd_stubs.c

Quoted 14 lines · Wei Liu
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Wei Liu

Clang complains:

systemd_stubs.c:51:8: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]

       ret = Val_int(-1U);
             ^~~~~~~~~~~~

Simply change the return value to 0.

Quoted 7 lines
Quoted 1 line

That will break the function though, as it previously returned -1.

I don't think the caller cares about the return value. The function signature is unit -> unit for sd_nofity_ready, and the return value is not checked at all. I admit I could have misread the code though.

Wei.

This is correct:

external sd_notify_ready: unit -> unit = "ocaml_sd_notify_ready"

Any return value can’t be observed on the OCaml side. It is a bit strange though that the C code does not return unit accordingly, which would be

return Val_unit;

— C

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [PATCH 2/2] ocaml: remove undefined behaviour in systemd_stubs.c

In reply to Wei Liu
Quoted 8 lines · Wei Liu
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Wei Liu

Clang complains:

systemd_stubs.c:51:8: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]

        ret = Val_int(-1U);
              ^~~~~~~~~~~~
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Simply change the return value to 0.

That will break the function though, as it previously returned -1.

I don't think the caller cares about the return value. The function signature is unit -> unit for sd_nofity_ready, and the return value is not checked at all. I admit I could have misread the code though.

Oh - in which case this is easy to fix.  You should return Val_unit

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel