Skip to contentSkip to conversation

bsd-user: silence warnings on OpenBSD

PATCH In review Peter Maydell 5 participants 16 messages Jul 18, 2017 – Jul 21, 2017

lore
Share & tools
lore
#0 lore raw

cover bsd-user: silence warnings on OpenBSD

I've just managed to get an OpenBSD VM into my test set for processing pull requests. There are a handful of minor compiler warnings in bsd-user, which this patchset fixes, just to reduce the noise in my logs.

thanks
-- PMM

Peter Maydell (4):
bsd-user/mmap.c: Move __thread attribute to right place bsd-user/elfload.c: Fix set-but-not-used warnings bsd-user/bsdload.c: Remove write-only id_change variable bsd-user/main.c: Fix unused variable warning

 bsd-user/bsdload.c | 25 +------------------------
 bsd-user/elfload.c | 10 ++++------
 bsd-user/main.c    |  7 ++++---
 bsd-user/mmap.c    |  2 +-
 4 files changed, 10 insertions(+), 34 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 bsd-user/mmap.c: Move __thread attribute to right place

Avoid a compiler warning on OpenBSD:
bsd-user/mmap.c:28:1: warning: '__thread' is not at beginning of declaration [-Wold-style-declaration] by moving the __thread attribute to its proper place.

---
 bsd-user/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bsd-user/mmap.c +1 -1
index 7f2018e..20cd29d 100644
@@ -25,7 +25,7 @@
 //#define DEBUG_MMAP
 
 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
-static int __thread mmap_lock_count;
+static __thread int mmap_lock_count;
 
 void mmap_lock(void)
 {
Signature · 1 line
2.7.4
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH for-2.10 1/4] bsd-user/mmap.c: Move __thread attribute to right place

Le 18 juil. 2017 1:29 PM, "Peter Maydell" <[email protected]> a écrit :

Quoted 28 lines

Avoid a compiler warning on OpenBSD:
bsd-user/mmap.c:28:1: warning: '__thread' is not at beginning of declaration [-Wold-style-declaration]
by moving the __thread attribute to its proper place.

---
 bsd-user/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bsd-user/mmap.c +1 -2
index 7f2018e..20cd29d 100644
@@ -25,7 +25,7 @@
 //#define DEBUG_MMAP
 
 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
-static int __thread mmap_lock_count;
+static __thread int mmap_lock_count;
 
 void mmap_lock(void)
 {
--

2.7.4

#3 lore raw

PATCH 2/4 bsd-user/elfload.c: Fix set-but-not-used warnings

In reply to Peter Maydell

Fix various warnings about set-but-not-used variables on OpenBSD:

bsd-user/elfload.c:1158:15: warning: variable 'mapped_addr' set but not used [-Wunused-but-set-variable] bsd-user/elfload.c:1165:9: warning: variable 'status' set but not used [-Wunused-but-set-variable] bsd-user/elfload.c:1168:15: warning: variable 'elf_stack' set but not used [-Wunused-but-set-variable]

---
 bsd-user/elfload.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
bsd-user/elfload.c +4 -6
index 41a1309..7cccf3e 100644
@@ -1155,21 +1155,20 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     unsigned int interpreter_type = INTERPRETER_NONE;
     unsigned char ibcs2_interpreter;
     int i;
-    abi_ulong mapped_addr;
     struct elf_phdr * elf_ppnt;
     struct elf_phdr *elf_phdata;
     abi_ulong elf_bss, k, elf_brk;
     int retval;
     char * elf_interpreter;
     abi_ulong elf_entry, interp_load_addr = 0;
-    int status;
     abi_ulong start_code, end_code, start_data, end_data;
     abi_ulong reloc_func_desc = 0;
-    abi_ulong elf_stack;
+#ifdef LOW_ELF_STACK
+    abi_ulong elf_stack = ~((abi_ulong)0UL);
+#endif
     char passed_fileno[6];
 
     ibcs2_interpreter = 0;
-    status = 0;
     load_addr = 0;
     load_bias = 0;
     elf_ex = *((struct elfhdr *) bprm->buf);          /* exec-header */
@@ -1221,7 +1220,6 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     elf_brk = 0;
 
 
-    elf_stack = ~((abi_ulong)0UL);
     elf_interpreter = NULL;
     start_code = ~((abi_ulong)0UL);
     end_code = 0;
@@ -1546,7 +1544,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
                and some applications "depend" upon this behavior.
                Since we do not have the power to recompile these, we
                emulate the SVr4 behavior.  Sigh.  */
-            mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
+            target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
                                       MAP_FIXED | MAP_PRIVATE, -1, 0);
     }
 
Signature · 1 line
2.7.4
Reviewed-by on v1 2/4
#4 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH for-2.10 2/4] bsd-user/elfload.c: Fix set-but-not-used warnings

Le 18 juil. 2017 1:32 PM, "Peter Maydell" <[email protected]> a écrit :

Quoted 69 lines

Fix various warnings about set-but-not-used variables on OpenBSD:

bsd-user/elfload.c:1158:15: warning: variable 'mapped_addr' set but not used [-Wunused-but-set-variable]
bsd-user/elfload.c:1165:9: warning: variable 'status' set but not used [-Wunused-but-set-variable]
bsd-user/elfload.c:1168:15: warning: variable 'elf_stack' set but not used [-Wunused-but-set-variable]

---
 bsd-user/elfload.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
bsd-user/elfload.c +3 -4
index 41a1309..7cccf3e 100644
@@ -1155,21 +1155,20 @@ int load_elf_binary(struct linux_binprm * bprm,
 struct target_pt_regs * regs,
     unsigned int interpreter_type = INTERPRETER_NONE;
     unsigned char ibcs2_interpreter;
     int i;
-    abi_ulong mapped_addr;
     struct elf_phdr * elf_ppnt;
     struct elf_phdr *elf_phdata;
     abi_ulong elf_bss, k, elf_brk;
     int retval;
     char * elf_interpreter;
     abi_ulong elf_entry, interp_load_addr = 0;
-    int status;
     abi_ulong start_code, end_code, start_data, end_data;
     abi_ulong reloc_func_desc = 0;
-    abi_ulong elf_stack;
+#ifdef LOW_ELF_STACK
+    abi_ulong elf_stack = ~((abi_ulong)0UL);
+#endif
     char passed_fileno[6];
 
     ibcs2_interpreter = 0;
-    status = 0;
     load_addr = 0;
     load_bias = 0;
     elf_ex = *((struct elfhdr *) bprm->buf);          /* exec-header */
bsd-user/elfload.c +0 -1
@@ -1221,7 +1220,6 @@ int load_elf_binary(struct linux_binprm * bprm,
 struct target_pt_regs * regs,
     elf_brk = 0;
 
 
-    elf_stack = ~((abi_ulong)0UL);
     elf_interpreter = NULL;
     start_code = ~((abi_ulong)0UL);
     end_code = 0;
bsd-user/elfload.c +1 -1
@@ -1546,7 +1544,7 @@ int load_elf_binary(struct linux_binprm * bprm,
 struct target_pt_regs * regs,
                and some applications "depend" upon this behavior.
                Since we do not have the power to recompile these, we
                emulate the SVr4 behavior.  Sigh.  */
-            mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ |
 PROT_EXEC,
+            target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
                                       MAP_FIXED | MAP_PRIVATE, -1, 0);
     }

--
2.7.4

#5 lore raw

PATCH 3/4 bsd-user/bsdload.c: Remove write-only id_change variable

In reply to Peter Maydell

On OpenBSD the compiler complains:
bsd-user/bsdload.c:54:17: warning: variable 'id_change' set but not used [-Wunused-but-set-variable]

This is dead code that was originally copied from linux-user. We fixed this in linux-user in commit 331c23b5ca44293d1 in 2011; delete the useless code from bsd-user too.

---
 bsd-user/bsdload.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
bsd-user/bsdload.c +1 -24
index 94eec36..f38c4fa 100644
@@ -20,22 +20,6 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
     return 0;
 }
 
-static int in_group_p(gid_t g)
-{
-    /* return TRUE if we're in the specified group, FALSE otherwise */
-    int         ngroup;
-    int         i;
-    gid_t       grouplist[TARGET_NGROUPS];
-
-    ngroup = getgroups(TARGET_NGROUPS, grouplist);
-    for(i = 0; i < ngroup; i++) {
-        if(grouplist[i] == g) {
-            return 1;
-        }
-    }
-    return 0;
-}
-
 static int count(char ** vec)
 {
     int         i;
@@ -51,7 +35,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
 {
     struct stat         st;
     int mode;
-    int retval, id_change;
+    int retval;
 
     if(fstat(bprm->fd, &st) < 0) {
         return(-errno);
@@ -67,14 +51,10 @@ static int prepare_binprm(struct linux_binprm *bprm)
 
     bprm->e_uid = geteuid();
     bprm->e_gid = getegid();
-    id_change = 0;
 
     /* Set-uid? */
     if(mode & S_ISUID) {
         bprm->e_uid = st.st_uid;
-        if(bprm->e_uid != geteuid()) {
-            id_change = 1;
-        }
     }
 
     /* Set-gid? */
@@ -85,9 +65,6 @@ static int prepare_binprm(struct linux_binprm *bprm)
      */
     if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
         bprm->e_gid = st.st_gid;
-        if (!in_group_p(bprm->e_gid)) {
-                id_change = 1;
-        }
     }
 
     memset(bprm->buf, 0, sizeof(bprm->buf));
Signature · 1 line
2.7.4
Reviewed-by on v1 3/4
#6 lore raw

Re: [Qemu-devel] [PATCH for-2.10 3/4] bsd-user/bsdload.c: Remove write-only id_change variable

Quoted 64 lines · Peter Maydell

On OpenBSD the compiler complains:
bsd-user/bsdload.c:54:17: warning: variable 'id_change' set but not used [-Wunused-but-set-variable]

This is dead code that was originally copied from linux-user. We fixed this in linux-user in commit 331c23b5ca44293d1 in 2011; delete the useless code from bsd-user too.

---
 bsd-user/bsdload.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
bsd-user/bsdload.c +1 -21
index 94eec36..f38c4fa 100644
@@ -20,22 +20,6 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
     return 0;
 }
 
-static int in_group_p(gid_t g)
-{
-    /* return TRUE if we're in the specified group, FALSE otherwise */
-    int         ngroup;
-    int         i;
-    gid_t       grouplist[TARGET_NGROUPS];
-
-    ngroup = getgroups(TARGET_NGROUPS, grouplist);
-    for(i = 0; i < ngroup; i++) {
-        if(grouplist[i] == g) {
-            return 1;
-        }
-    }
-    return 0;
-}
-
 static int count(char ** vec)
 {
     int         i;
@@ -51,7 +35,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
 {
     struct stat         st;
     int mode;
-    int retval, id_change;
+    int retval;
 
     if(fstat(bprm->fd, &st) < 0) {
         return(-errno);
@@ -67,14 +51,10 @@ static int prepare_binprm(struct linux_binprm *bprm)
 
     bprm->e_uid = geteuid();
     bprm->e_gid = getegid();
-    id_change = 0;
 
     /* Set-uid? */
     if(mode & S_ISUID) {
         bprm->e_uid = st.st_uid;
-        if(bprm->e_uid != geteuid()) {
-            id_change = 1;
-        }
     }
 
     /* Set-gid? */

bsd-user/bsdload.c static int prepare_binprm(struct linux_binprm *bprm) · line 70

Quoted 9 lines
bsd-user/bsdload.c +0 -3
@@ -85,9 +65,6 @@ static int prepare_binprm(struct linux_binprm *bprm)
      */
     if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
         bprm->e_gid = st.st_gid;
-        if (!in_group_p(bprm->e_gid)) {
-                id_change = 1;
-        }
     }
 
     memset(bprm->buf, 0, sizeof(bprm->buf));

Matches the commit from linux-user, and looks sane to me, so:

#7 lore raw

Re: [Qemu-devel] [PATCH for-2.10 3/4] bsd-user/bsdload.c: Remove write-only id_change variable

Quoted 8 lines · Thomas Huth
Quoted 7 lines · Peter Maydell

On OpenBSD the compiler complains:
bsd-user/bsdload.c:54:17: warning: variable 'id_change' set but not used [-Wunused-but-set-variable]

This is dead code that was originally copied from linux-user. We fixed this in linux-user in commit 331c23b5ca44293d1 in 2011; delete the useless code from bsd-user too.

Quoted 7 lines
Quoted 2 lines

---

Matches the commit from linux-user, and looks sane to me, so:

Thanks; applied to master.

-- PMM

#8 lore raw

PATCH 4/4 bsd-user/main.c: Fix unused variable warning

In reply to Peter Maydell

On OpenBSD the compiler warns:
bsd-user/main.c:622:21: warning: variable 'sig' set but not used [-Wunused-but-set-variable]

This is because a lot of the signal delivery code is #if-0'd out as unused. Reshuffle #ifdefs a bit to silence the warning.

---
 bsd-user/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
bsd-user/main.c +4 -3
index fa9c012..501e16f 100644
@@ -619,9 +619,10 @@ void cpu_loop(CPUSPARCState *env)
             break;
         case EXCP_DEBUG:
             {
-                int sig;
-
-                sig = gdb_handlesig(cs, TARGET_SIGTRAP);
+#if 0
+                int sig =
+#endif
+                gdb_handlesig(cs, TARGET_SIGTRAP);
 #if 0
                 if (sig)
                   {
Signature · 1 line
2.7.4
#9 lore raw

Re: [Qemu-devel] [PATCH for-2.10 4/4] bsd-user/main.c: Fix unused variable warning

Quoted 5 lines · Peter Maydell

On OpenBSD the compiler warns:
bsd-user/main.c:622:21: warning: variable 'sig' set but not used [-Wunused-but-set-variable]

This is because a lot of the signal delivery code is #if-0'd out as unused. Reshuffle #ifdefs a bit to silence the warning.

Why not just nuke the #if 0 code instead (we can always 'git revert' it later as a starting point for someone that wants to implement it).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH for-2.10 4/4] bsd-user/main.c: Fix unused variable warning

Quoted 9 lines · Eric Blake
Quoted 5 lines · Peter Maydell

On OpenBSD the compiler warns:
bsd-user/main.c:622:21: warning: variable 'sig' set but not used [-Wunused-but-set-variable]

This is because a lot of the signal delivery code is #if-0'd out as unused. Reshuffle #ifdefs a bit to silence the warning.

Why not just nuke the #if 0 code instead (we can always 'git revert' it later as a starting point for someone that wants to implement it).

I went for the minimal change, especially given we know that the freebsd folks have a big patchset on top of us fixing a lot of bsd-user code and it didn't seem worth giving them a more awkward rebase task.

thanks
-- PMM

Reviewed-by
#11 lore raw

Re: [Qemu-devel] [PATCH for-2.10 4/4] bsd-user/main.c: Fix unused variable warning

Quoted 8 lines · Peter Maydell
Quoted 7 lines · Eric Blake
Quoted 5 lines · Peter Maydell

On OpenBSD the compiler warns:
bsd-user/main.c:622:21: warning: variable 'sig' set but not used [-Wunused-but-set-variable]

This is because a lot of the signal delivery code is #if-0'd out as unused. Reshuffle #ifdefs a bit to silence the warning.

Quoted 7 lines
Quoted 2 lines

Why not just nuke the #if 0 code instead (we can always 'git revert' it later as a starting point for someone that wants to implement it).

I went for the minimal change, especially given we know that the freebsd folks have a big patchset on top of us fixing a lot of bsd-user code and it didn't seem worth giving them a more awkward rebase task.

That's fair. So FWIW:

Reviewed-by
#12 lore raw

Re: [Qemu-devel] [PATCH for-2.10 4/4] bsd-user/main.c: Fix unused variable warning

In reply to Peter Maydell
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Eric Blake
Quoted 5 lines · Peter Maydell

On OpenBSD the compiler warns:
bsd-user/main.c:622:21: warning: variable 'sig' set but not used [-Wunused-but-set-variable]

This is because a lot of the signal delivery code is #if-0'd out as unused. Reshuffle #ifdefs a bit to silence the warning.

Quoted 7 lines
Quoted 2 lines

Why not just nuke the #if 0 code instead (we can always 'git revert' it later as a starting point for someone that wants to implement it).

I went for the minimal change, especially given we know that the freebsd folks have a big patchset on top of us fixing a lot of bsd-user code and it didn't seem worth giving them a more awkward rebase task.

Perhaps worth mentioning in the commit message that keeping the #if 0 is intentional, then. At any rate,

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH for-2.10 4/4] bsd-user/main.c: Fix unused variable warning

Quoted 17 lines · Eric Blake
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Eric Blake
Quoted 5 lines · Peter Maydell

On OpenBSD the compiler warns:
bsd-user/main.c:622:21: warning: variable 'sig' set but not used [-Wunused-but-set-variable]

This is because a lot of the signal delivery code is #if-0'd out as unused. Reshuffle #ifdefs a bit to silence the warning.

Quoted 7 lines
Quoted 2 lines

Why not just nuke the #if 0 code instead (we can always 'git revert' it later as a starting point for someone that wants to implement it).

I went for the minimal change, especially given we know that the freebsd folks have a big patchset on top of us fixing a lot of bsd-user code and it didn't seem worth giving them a more awkward rebase task.

Quoted 4 lines

Perhaps worth mentioning in the commit message that keeping the #if 0 is intentional, then. At any rate,

Thanks; applied to master with an updated commit message.

-- PMM

#14 lore raw
In reply to Peter Maydell
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PATCH for-2.10 0/4] bsd-user: silence warnings on OpenBSD
Message-id: [email protected]
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
2205391 bsd-user/main.c: Fix unused variable warning 72ca90a bsd-user/bsdload.c: Remove write-only id_change variable 8d5f872 bsd-user/elfload.c: Fix set-but-not-used warnings 684257a bsd-user/mmap.c: Move __thread attribute to right place

=== OUTPUT BEGIN ===
Checking PATCH 1/4: bsd-user/mmap.c: Move __thread attribute to right place... Checking PATCH 2/4: bsd-user/elfload.c: Fix set-but-not-used warnings... Checking PATCH 3/4: bsd-user/bsdload.c: Remove write-only id_change variable... Checking PATCH 4/4: bsd-user/main.c: Fix unused variable warning...
ERROR: if this code is redundant consider removing it
#26: FILE: bsd-user/main.c:622:
+#if 0

total: 1 errors, 0 warnings, 13 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#15 lore raw
In reply to Peter Maydell
Quoted 5 lines · Peter Maydell

I've just managed to get an OpenBSD VM into my test set for processing pull requests. There are a handful of minor compiler warnings in bsd-user, which this patchset fixes, just to reduce the noise in my logs.

Quoted 8 lines

thanks
-- PMM

Peter Maydell (4):
bsd-user/mmap.c: Move __thread attribute to right place bsd-user/elfload.c: Fix set-but-not-used warnings bsd-user/bsdload.c: Remove write-only id_change variable bsd-user/main.c: Fix unused variable warning

I've applied patches 1 and 2 to master; patch 3 still awaiting review and 4 review/reply to my response-to-review...

thanks
-- PMM