Project

General

Profile

Actions

Bug #3251

closed

[1.4.76] buildroot compile error with bootlin-sparc{64-g,-uc}libc

Added by ThomasDevoogdt 28 days ago. Updated 26 days ago.

Status:
Fixed
Priority:
Normal
Category:
core
Target version:
ASK QUESTIONS IN Forums:
No

Description

Hi,

I noticed a compile error on the Sparc platform while bumping lighttpd in Buildroot.

bootlin-sparc-uclibc:

FAILED: src/lighttpd.p/fdevent_impl.c.o 
/home/thomas/br-test-pkg/bootlin-sparc-uclibc/host/bin/sparc-linux-gcc -Isrc/lighttpd.p -Isrc -I../src -I/home/thomas/br-test-pkg/bootlin-sparc-uclibc/host/sparc-buildroot-linux-uclibc/sysroot/usr/local/include -fdiagnostics-color=always -Wall -Winvalid-pch -std=c11 -O3 -D_LARGEFILE64_SOURCE -O2 -g0 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_DEFAULT_SOURCE -D_GNU_SOURCE -DHAVE_CONFIG_H -pipe -Wall -g -Wshadow -W -pedantic -MD -MQ src/lighttpd.p/fdevent_impl.c.o -MF src/lighttpd.p/fdevent_impl.c.o.d -o src/lighttpd.p/fdevent_impl.c.o -c ../src/fdevent_impl.c
In file included from ../src/ck.h:121,
                 from ../src/buffer.h:407,
                 from ../src/fdevent_impl.c:5:
../src/fdevent_impl.c: In function ‘fdevent_linux_sysepoll_init’:
../src/ck.h:125:29: error: static assertion failed: "EPOLLRDHUP == FDEVENT_RDHUP" 
  125 | #define ck_static_assert(x) static_assert((x),#x)
      |                             ^~~~~~~~~~~~~
../src/fdevent_impl.c:379:5: note: in expansion of macro ‘ck_static_assert’
  379 |     ck_static_assert(EPOLLRDHUP == FDEVENT_RDHUP);
      |     ^~~~~~~~~~~~~~~~

bootlin-sparc64-glibc:

FAILED: src/lighttpd.p/fdevent_impl.c.o 
/home/thomas/br-test-pkg/bootlin-sparc64-glibc/host/bin/sparc64-linux-gcc -Isrc/lighttpd.p -Isrc -I../src -I/home/thomas/br-test-pkg/bootlin-sparc64-glibc/host/sparc64-buildroot-linux-gnu/sysroot/usr/local/include -fdiagnostics-color=always -Wall -Winvalid-pch -std=c11 -O3 -D_LARGEFILE64_SOURCE -O2 -g0 -D_FORTIFY_SOURCE=1 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_DEFAULT_SOURCE -D_GNU_SOURCE -DHAVE_CONFIG_H -pipe -Wall -g -Wshadow -W -pedantic -MD -MQ src/lighttpd.p/fdevent_impl.c.o -MF src/lighttpd.p/fdevent_impl.c.o.d -o src/lighttpd.p/fdevent_impl.c.o -c ../src/fdevent_impl.c
In file included from ../src/ck.h:121,
                 from ../src/buffer.h:407,
                 from ../src/fdevent_impl.c:5:
../src/fdevent_impl.c: In function ‘fdevent_linux_sysepoll_init’:
../src/ck.h:125:29: error: static assertion failed: "EPOLLRDHUP == FDEVENT_RDHUP" 
  125 | #define ck_static_assert(x) static_assert((x),#x)
      |                             ^~~~~~~~~~~~~
../src/fdevent_impl.c:379:5: note: in expansion of macro ‘ck_static_assert’
  379 |     ck_static_assert(EPOLLRDHUP == FDEVENT_RDHUP);
      |     ^~~~~~~~~~~~~~~~

Reproduction:

$ git clone https://gitlab.com/buildroot.org/buildroot.git
$ cd buildroot/
$ curl https://patchwork.ozlabs.org/series/403994/mbox/ | git am
$ ./utils/test-pkg -p lighttpd -a
$ cat ~/br-test-pkg/bootlin-sparc-uclibc/logfile
$ cat ~/br-test-pkg/bootlin-sparc64-glibc/logfile

Files

logfile (3.41 MB) logfile bootlin-sparc64-glibc ThomasDevoogdt, 2024-04-22 20:53
logfile (990 KB) logfile bootlin-sparc-uclibc ThomasDevoogdt, 2024-04-22 20:53
0002-core-fix-POLLRDHUP-on-SPARC-fixes-3251.patch (2.7 KB) 0002-core-fix-POLLRDHUP-on-SPARC-fixes-3251.patch ThomasDevoogdt, 2024-04-24 17:27
Actions #1

Updated by gstrauss 28 days ago

  • Category set to core
  • Target version changed from 1.4.xx to 1.4.77

What is the value of EPOLLRDHUP on that system? I had added logic in lighttpd 1.4.76 (commit f14f9142) in an attempt to fix the build issue on Debian sparc64
https://buildd.debian.org/status/fetch.php?pkg=lighttpd&arch=sparc64&ver=1.4.74-2&stamp=1709590155&raw=0

If the value with uclibc on Linux on sparc64 is 0x2000, as is on most Linux, and not 0x0800 as is on glibc on sparc64, then I'll adjust the special-case to check for __GLIBC__, too.

Ultimately, the workaround for you is to adjust the value of FDEVENT_RDHUP in fdevent.h.

The value is hard-coded to encapsulate the system-specific values rather than expose extra system headers, but lighttpd has a static_assert() to ensure that the values match in fdevent_impl.c

Actions #2

Updated by gstrauss 28 days ago

  • Status changed from New to Patch Pending

I am going to revert commit f14f9142 in lighttpd 1.4.77 until I can get more info about the failing static_assert() on Debian sparc64 build.

Actions #3

Updated by gstrauss 28 days ago

  • Status changed from Patch Pending to Fixed
Actions #4

Updated by ThomasDevoogdt 27 days ago

Hi,

Sorry for the late answer.
I checked the patch, but I think you were a little bit too fast.
There is apparently POLLRDHUP and EPOLLRDHUP, for which there are two static asserts with FDEVENT_RDHUP.
But since the two are not the same, there will always be one of the two that fails.

../src/fdevent_impl.c:379:5: note: in expansion of macro ‘ck_static_assert’
  379 |     ck_static_assert(EPOLLRDHUP == FDEVENT_RDHUP);
      |     ^~~~~~~~~~~~~~~~

../src/fdevent_impl.c:857:5: note: in expansion of macro ‘ck_static_assert’
  857 |     ck_static_assert(POLLRDHUP == FDEVENT_RDHUP);
      |     ^~~~~~~~~~~~~~~~

bootlin-sparc-uclibc:

~/br-test-pkg/bootlin-sparc-uclibc$ grep -r "POLLRDHUP" host/sparc-buildroot-linux-uclibc/sysroot/usr/include
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/linux/eventpoll.h:#define EPOLLRDHUP    0x00002000
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/bits/poll.h:# define POLLRDHUP    0x800
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/sys/epoll.h:    EPOLLRDHUP = 0x2000,
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/sys/epoll.h:#define EPOLLRDHUP EPOLLRDHUP
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/asm-generic/poll.h:#ifndef POLLRDHUP
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/asm-generic/poll.h:#define POLLRDHUP       0x2000
host/sparc-buildroot-linux-uclibc/sysroot/usr/include/asm/poll.h:#define POLLRDHUP       2048

bootlin-sparc64-glibc:

~/br-test-pkg/bootlin-sparc64-glibc$ grep -r "POLLRDHUP" host/sparc64-buildroot-linux-gnu/sysroot/usr/include
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/linux/eventpoll.h:#define EPOLLRDHUP    (__poll_t)0x00002000
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/bits/poll.h:# define POLLRDHUP    0x800
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/sys/epoll.h:    EPOLLRDHUP = 0x2000,
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/sys/epoll.h:#define EPOLLRDHUP EPOLLRDHUP
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/asm-generic/poll.h:#ifndef POLLRDHUP
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/asm-generic/poll.h:#define POLLRDHUP       0x2000
host/sparc64-buildroot-linux-gnu/sysroot/usr/include/asm/poll.h:#define POLLRDHUP       2048

So in short:

#define EPOLLRDHUP 0x2000

#define POLLRDHUP 0x0800

Note that 2048 = 0x0800.

Kr,

Thomas Devoogdt

Actions #5

Updated by gstrauss 26 days ago

Thanks for the info. I don't have those systems on which to test. (Tips or links to doc would be appreciated)

My initial reaction is that it is unfortunate that there are different flag values for POLLRDHUP and EPOLLRDHUP -- apparently only on Linux on SPARC?

Actions #6

Updated by gstrauss 26 days ago · Edited

This might work since lighttpd use of lighttpd FDEVENT_RDHUP checks for flags existing, not exact match.

--- a/src/fdevent.h
+++ b/src/fdevent.h
@@ -40,6 +40,8 @@ struct fdnode_st {
 #if (defined(__sun) && defined(__SVR4)) /* Solaris */ \
  || defined(__FreeBSD__)
 #define FDEVENT_RDHUP  0x4000
+#elif (defined(__linux__) && (defined(__sparc__) || defined(__sparc)))
+#define FDEVENT_RDHUP  0x2800 /*(0x2000 EPOLLRDHUP | 0x0800 POLLRDHUP)*/
 #else
 #define FDEVENT_RDHUP  0x2000
 #endif
--- a/src/fdevent_impl.c
+++ b/src/fdevent_impl.c
@@ -338,6 +338,11 @@ fdevent_linux_sysepoll_event_set (fdevents *ev, fdnode *fdn, int events)
     struct epoll_event ep;
   #ifndef EPOLLRDHUP
     events &= ~FDEVENT_RDHUP;
+  #elif (defined(__linux__) && (defined(__sparc__) || defined(__sparc)))
+    if (events & FDEVENT_RDHUP) {
+        events &= ~FDEVENT_RDHUP;
+        events |= EPOLLRDHUP;
+    }
   #endif
     ep.events = events | EPOLLERR | EPOLLHUP;
     ep.data.ptr = fdn;
@@ -376,7 +381,11 @@ fdevent_linux_sysepoll_init (fdevents *ev)
     ck_static_assert(EPOLLERR   == FDEVENT_ERR);
     ck_static_assert(EPOLLHUP   == FDEVENT_HUP);
   #ifdef EPOLLRDHUP
+   #if (defined(__linux__) && (defined(__sparc__) || defined(__sparc)))
+    ck_static_assert(EPOLLRDHUP  & FDEVENT_RDHUP);
+   #else
     ck_static_assert(EPOLLRDHUP == FDEVENT_RDHUP);
+   #endif
   #endif

     ev->type      = FDEVENT_HANDLER_LINUX_SYSEPOLL;
@@ -770,6 +779,11 @@ fdevent_poll_event_set (fdevents *ev, fdnode *fdn, int events)

   #ifndef POLLRDHUP
     events &= ~FDEVENT_RDHUP;
+  #elif (defined(__linux__) && (defined(__sparc__) || defined(__sparc)))
+    if (events & FDEVENT_RDHUP) {
+        events &= ~FDEVENT_RDHUP;
+        events |= POLLRDHUP;
+    }
   #endif

     if (k >= 0) {
@@ -854,7 +868,11 @@ fdevent_poll_init (fdevents *ev)
     ck_static_assert(POLLHUP   == FDEVENT_HUP);
     ck_static_assert(POLLNVAL  == FDEVENT_NVAL);
   #ifdef POLLRDHUP
+   #if (defined(__linux__) && (defined(__sparc__) || defined(__sparc)))
+    ck_static_assert(POLLRDHUP  & FDEVENT_RDHUP);
+   #else
     ck_static_assert(POLLRDHUP == FDEVENT_RDHUP);
+   #endif
   #endif

     ev->type      = FDEVENT_HANDLER_POLL;
Actions #7

Updated by ThomasDevoogdt 26 days ago

Hi,

I can confirm that the build is fixed with this. But I didn't run any real-life tests since I don't have the hardware. For that, we will have to wait until Buildroot folks pick this up for their projects.

Kr,

Thomas

Actions #8

Updated by gstrauss 26 days ago

@ThomasDevoogdt Thank you for testing the build and packaging the patch.

It is likely that only lighttpd epoll (the default lighttpd event handler on Linux) worked in buildroot on Linux on SPARC up until lighttpd 1.4.74 when I changed some runtime asserts to C11 static_assert(), resulting in the assertion failures you reported above.

Actions

Also available in: Atom