Bug 18957 - Error: static declaration of setns follows non-static declaration
Summary: Error: static declaration of setns follows non-static declaration
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-12 12:24 UTC by Dan Collins
Modified: 2021-11-09 08:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Collins 2015-09-12 12:24:57 UTC
Greetings,

While compiling GDB 7.10 on the following system:

dcollins@****~$ uname -a
Linux **** 2.6.32-5-686 #1 SMP Tue May 13 16:33:32 UTC 2014 i686 GNU/Linux

With toolchain versions:
GCC 5.2.0
glibc 2.22
binutils 2.25

by executing the following commands:
./Configure && make

I received the following error:

gcc -g -O2   -I. -I. -I./common -I./config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I./../zlib -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber  -I./gnulib/import -Ibuild-gnulib/import    -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wpointer-sign -Wmissing-prototypes -Wdeclaration-after-statement -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wformat-nonliteral  -c -o linux-namespaces.o -MT linux-namespaces.o -MMD -MP -MF .deps/linux-namespaces.Tpo ./nat/linux-namespaces.c
./nat/linux-namespaces.c:39:1: error: static declaration of ‘setns’ follows non-static declaration
 setns (int fd, int nstype)
 ^
In file included from /usr/include/sched.h:43:0,
                 from ./nat/linux-namespaces.c:30:
/usr/include/bits/sched.h:91:12: note: previous declaration of ‘setns’ was here
 extern int setns (int __fd, int __nstype) __THROW;
            ^
make[2]: *** [linux-namespaces.o] Error 1
make[2]: Leaving directory `/home/dcollins/gdb-7.10/gdb'
make[1]: *** [all-gdb] Error 2
make[1]: Leaving directory `/home/dcollins/gdb-7.10'
make: *** [all] Error 2

Modifying line 38 of gdb/nat/linux-namespaces.c to remove the static declaration allowed compilation to continue without error. GDB Configure should determine whether the preexisting setns is declared with or without static and should follow that convention to prevent this compile error.
Comment 1 Sourceware Commits 2015-09-14 10:06:09 UTC
The gdb-7.10-branch branch has been updated by Gary Benson <gary@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a8c636cb54328fb9a71dcf27b66a7e7ab5443d88

commit a8c636cb54328fb9a71dcf27b66a7e7ab5443d88
Author: Gary Benson <gbenson@redhat.com>
Date:   Mon Sep 14 11:02:06 2015 +0100

    Fix build issue with nat/linux-namespaces.c
    
    This commit fixes a build issue on systems with a prototype for setns
    in their header files but no working setns is detected by configure.
    
    gdb/ChangeLog:
    
    	PR gdb/18957
    	* nat/linux-namespaces.c (setns): Rename from this ...
    	(do_setns): ... to this.  Support calling setns if it exists.
    	(mnsh_handle_setns): Call do_setns.
Comment 2 Gary Benson 2015-09-14 10:12:49 UTC
Hi Dan,

This was fixed in gdb/master but it didn't get pushed to the 7.10 branch.
I've pushed it there now.

Thanks for reporting this.

Cheers,
Gary
Comment 3 Stewart 2021-11-09 08:28:53 UTC Comment hidden (spam)