[binutils-gdb/gdb-17-branch] gdb/ser-unix: work around conflicting types for tcflag_t

Sam James via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2636da31af44fab38c22cee0fe771761173ea64b

commit 2636da31af44fab38c22cee0fe771761173ea64b
Author: Simon Marchi <[email protected]>
Date:   Mon Nov 17 16:25:18 2025 -0500

    gdb/ser-unix: work around conflicting types for tcflag_t
    
    When trying to cross-compile GDB to sparc-buildroot-linux-uclibc, I get:
    
          CXX    ser-unix.o
        In file included from /data1/smarchi/many-buildroots/toolchains/sparc/sparc-buildroot-linux-uclibc/sysroot/usr/include/termios.h:39,
                         from /home/smarchi/src/binutils-gdb/gdb/ser-unix.c:51:
        /data1/smarchi/many-buildroots/toolchains/sparc/sparc-buildroot-linux-uclibc/sysroot/usr/include/bits/termios.h:26:22: error: conflicting declaration ‘typedef unsigned int tcflag_t’
           26 | typedef unsigned int tcflag_t;
              |                      ^~~~~~~~
        In file included from /home/smarchi/src/binutils-gdb/gdb/ser-unix.c:46:
        /data1/smarchi/many-buildroots/toolchains/sparc/sparc-buildroot-linux-uclibc/sysroot/usr/include/asm/termbits.h:13:25: note: previous declaration as ‘typedef long unsigned int tcflag_t’
           13 | typedef unsigned long   tcflag_t;
              |                         ^~~~~~~~
    
    uClibc and the kernel don't agree on the definition of tcflag_t for this
    architecture.  Here' uClibc [1]:
    
        typedef unsigned int tcflag_t;
    
    And here's the kernel [2]:
    
        #if defined(__sparc__) && defined(__arch64__)
        typedef unsigned int        tcflag_t;
        #else
        typedef unsigned long       tcflag_t; <--- that branch is take
        #endif
    
    glibc [3] has the same definition as uClibc, so we would get the same
    problem.
    
    I propose to work around this the same way as we handle differences in
    the termios structure, by renaming the version from the kernel.
    
    I opened a bug on the glibc bugzilla [4] to ask if this is something
    that would need to be fixed on the libc side, but in the mean time we
    need to work around it.
    
    [1] https://github.com/kraj/uClibc/blob/ca1c74d67dd115d059a875150e10b8560a9c35a8/libc/sysdeps/linux/sparc/bits/termios.h#L26
    [2] https://github.com/torvalds/linux/blob/e7c375b181600caf135cfd03eadbc45eb530f2cb/arch/sparc/include/uapi/asm/termbits.h#L7-L11
    [3] https://gitlab.com/gnutools/glibc/-/blob/efc8642051e6c4fe5165e8986c1338ba2c180de6/bits/termios.h#L104
    [4] https://sourceware.org/bugzilla/show_bug.cgi?id=33643
    
    Change-Id: I71c6e0df5ac8e2ff3db3233a2220faaf70c3df6d
    Approved-By: Tom Tromey <[email protected]>
    (cherry picked from commit 6b84377e146794446f21371f8455b870a029cc8e)

Diff:
---
 gdb/ser-unix.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 5ec664df1f3..50c0fdddf6d 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -43,8 +43,10 @@
 /* Workaround to resolve conflicting declarations of termios
    in <asm/termbits.h> and <termios.h>.  */
 #  define termios asmtermios
+#  define tcflag_t asmtcflag_t
 #  include <asm/termbits.h>
 #  undef termios
+#  undef tcflag_t
 #endif
 
 #ifdef HAVE_TERMIOS_H
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.