Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 741490

Summary: media-libs/libsdl2-2.0.12-r2 build error with VIDEO_CARDS="vc4"
Product: Gentoo Linux Reporter: hangglider
Component: Current packagesAssignee: Gentoo Games <games>
Status: UNCONFIRMED ---    
Severity: normal CC: a.deligiannidis, brad, crabbedhaloablution, gem, gl, herrtimson, hfern, jstein, korte, muriloglix, sam
Priority: Normal Keywords: PATCH
Version: unspecified   
Hardware: ARM64   
OS: Linux   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=824270
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: build.log
emerge --info output
vc4_f_ok.patch
fix linking libvchostif library
libsdl2 updated ebuild
consolidated patch.
User patch for libsdl2-2.0.16-r1

Description hangglider 2020-09-10 08:18:29 UTC
Created attachment 659366 [details]
build.log

Ebuild has the following problems:

(1) missing #include <unistd.h> (trivial, inserted):

/var/tmp/portage/media-libs/libsdl2-2.0.12-r2/work/SDL2-2.0.12/src/video/SDL_egl.c:289:53: error: 'F_OK' undeclared (first use in this function)                                                                                             
  289 |     SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));                                                                                                                                                                          
      |                                                     ^~~~                                                                                                                                                                             
/var/tmp/portage/media-libs/libsdl2-2.0.12-r2/work/SDL2-2.0.12/src/video/SDL_egl.c:289:53: note: each undeclared identifier is reported only once for each function it appears in

(2) unknown symbol EGL_DISPMANX_WINDOW_T:

/var/tmp/portage/media-libs/libsdl2-2.0.12-r2/work/SDL2-2.0.12/src/video/raspberry/SDL_rpivideo.h:47:5: error: unknown type name 'EGL_DISPMANX_WINDOW_T'
   47 |     EGL_DISPMANX_WINDOW_T dispman_window;

The only difference from *-2.0.12-r1 seems to be the rather trivial patch libsdl2-2.0.12-egl-detection.patch
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-09-10 15:10:19 UTC
emerge --info please, and could you report this upstream too? They're quite responsive.

Does -r1 build fine, given your comment?
Comment 2 hangglider 2020-09-11 20:27:03 UTC
Created attachment 659560 [details]
emerge --info output

emerge --info output attached.

-r1 exposes the same problems, so (1) the mentioned additional patch can't be the cause of that and (2) there must have been some infrastructure change in the meantime leading to the mentioned problem(s) getting exposed. This dates back to April 19th, where it tooks a few tries to install media-libs/libsdl2-2.0.12-r1 for media-libs/libsdl2-2.0.12, according to my log files (I'd assume the access() problem where I simply inserted the #include line).

Will try to find some morehints before reporting it upstream too.
Comment 3 James Le Cuirot gentoo-dev 2020-09-30 15:35:48 UTC
Both of these are specific to the vc4 (Raspberry Pi) video driver.
Comment 4 Bug 2020-10-09 03:09:11 UTC
Same behaviour on my Raspberry Pi
Comment 5 Argyrios Deligiannidis 2020-11-11 06:49:00 UTC
I can confirm that it happens both for media-libs/libsdl2-2.0.12-r1 and media-libs/libsdl2-2.0.12-r2 on a chroot arm64 build environment.
Comment 6 Argyrios Deligiannidis 2020-11-11 08:09:25 UTC
Created attachment 670840 [details, diff]
vc4_f_ok.patch

So, I managed to succefully build the package:

First by including the header files for raspberry:

--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -45,6 +45,11 @@
 
 #if SDL_VIDEO_DRIVER_RPI
 /* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
+#include "raspberry/SDL_rpievents_c.h"
+#include "raspberry/SDL_rpiopengles.h"
+#include "raspberry/SDL_rpimouse.h"
+#include "raspberry/SDL_rpivideo.h"
+#define F_OK 0
 #define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
 #define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" )
 #define ALT_EGL "libEGL.so"

Then I was greeted with the following error:

/media/RamDisk/portage/media-libs/libsdl2-2.0.12-r2/work/SDL2-2.0.12/src/video/raspberry/SDL_rpivideo.h:47:5: error: unknown type name ‘EGL_DISPMANX_WINDOW_T’
   47 |     EGL_DISPMANX_WINDOW_T dispman_window;
      |     ^~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:536: build/SDL_egl.lo] Error 1


Which was solved by adding:

--- a/src/video/raspberry/SDL_rpivideo.h
+++ b/src/video/raspberry/SDL_rpivideo.h
@@ -41,6 +41,12 @@
     DISPMANX_DISPLAY_HANDLE_T dispman_display;
 } SDL_DisplayData;
 
+
+typedef struct {
+    DISPMANX_ELEMENT_HANDLE_T element;
+    int width;
+    int height;
+ } EGL_DISPMANX_WINDOW_T;
 
 typedef struct SDL_WindowData
 {
Comment 7 hangglider 2020-12-30 16:56:11 UTC
Same problem as in comment 6 here, any idea where EGL_DISPMANX_WINDOW_T is usually defined?
Comment 8 hangglider 2020-12-30 17:54:11 UTC
Didn't recognise (last) patch, please ignore comment 7.

Had another problem when linking, as -lvchostif was missed from link command:

/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: build/.libs/SDL_rpimouse.o: in function `RPI_WarpMouseGlobal':                                                                                    
SDL_rpimouse.c:(.text+0x7c): undefined reference to `vc_dispmanx_update_start'                                                                                                                                                               
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: SDL_rpimouse.c:(.text+0x104): undefined reference to `vc_dispmanx_element_change_attributes'                                                      
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: SDL_rpimouse.c:(.text+0x118): undefined reference to `vc_dispmanx_update_submit'                                                                  
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: build/.libs/SDL_rpimouse.o: in function `RPI_MoveCursor':                                                                                         
SDL_rpimouse.c:(.text+0x1e0): undefined reference to `vc_dispmanx_update_start'                                                                                                                                                              
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: SDL_rpimouse.c:(.text+0x248): undefined reference to `vc_dispmanx_element_change_attributes'                                                      
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: SDL_rpimouse.c:(.text+0x25c): undefined reference to `vc_dispmanx_update_submit'                                                                  
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: build/.libs/SDL_rpimouse.o: in function `RPI_ShowCursor':                                                                                         
SDL_rpimouse.c:(.text+0x390): undefined reference to `vc_dispmanx_rect_set'
...
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-30 18:23:37 UTC
Is there an upstream bug for this?

Also, does the patch work for you?
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-30 18:24:11 UTC
(In reply to Sam James from comment #9)
> Is there an upstream bug for this?
> 
> Also, does the patch work for you?

Ah, missed last comment.
Comment 11 Gary E. Miller 2021-01-11 21:54:02 UTC
These versions fail for me:

=media-libs/libsdl2-2.0.14-r1
=media-libs/libsdl2-2.0.14
=media-libs/libsdl2-2.0.12-r1
=media-libs/libsdl2-2.0.12-r2

This one works for me:

=media-libs/libsdl2-2.0.12
Comment 12 Perry Gilfillan 2021-01-30 00:20:19 UTC
I'm happy to report that the patch, attachment 670840 [details, diff], works for me!  Havn't got anything linking to it to test yet, so if things are still wonky I'll be back.

My trio of Pi4's can go back to churning out more builds!
Comment 13 Guillaume Lespinasse 2021-02-25 15:48:16 UTC
The patch from #6 helps me get past the error from #1 (thank you!), but my build fails further down at link time, same as #8

libtool: link: aarch64-unknown-linux-gnu-ranlib build/.libs/libSDL2_test.a
libtool: link: ( cd "build/.libs" && rm -f "libSDL2_test.la" && ln -s "../libSDL2_test.la" "libSDL2_test.la" )
/usr/lib/gcc/aarch64-unknown-linux-gnu/10.2.0/../../../../aarch64-unknown-linux-gnu/bin/ld: build/.libs/SDL_rpimouse.o: in function `RPI_WarpMouseGlobal':
SDL_rpimouse.c:(.text+0x7c): undefined reference to `vc_dispmanx_update_start'
/usr/lib/gcc/aarch64-unknown-linux-gnu/10.2.0/../../../../aarch64-unknown-linux-gnu/bin/ld: SDL_rpimouse.c:(.text+0x104): undefined reference to `vc_dispmanx_element_change_attributes'
/usr/lib/gcc/aarch64-unknown-linux-gnu/10.2.0/../../../../aarch64-unknown-linux-gnu/bin/ld: SDL_rpimouse.c:(.text+0x118): undefined reference to `vc_dispmanx_update_submit'

etc
Comment 14 Guillaume Lespinasse 2021-02-25 16:37:46 UTC
It does build fine with VIDEO_CARDS="-vc4"



When vc4 is set however, libsdl2 seems to be trying to access a now unused set of folders, sample:

libtool: compile:  aarch64-unknown-linux-gnu-gcc -mtune=cortex-a72 -march=armv8-a+crc -pipe -Wl,-O1 -Wl,--as-needed -O2 -D__LINUX__ -DUSING_GENERATED_CONFIG_H -Iinclude -I/var/tmp/portage/media-libs/libsdl2-2.0.14-r1/work/SDL2-2.0.14-.arm64/include -idirafter /var/tmp/portage/media-libs/libsdl2-2.0.14-r1/work/SDL2-2.0.14-.arm64/src/video/khronos -Wall -fno-strict-aliasing -fvisibility=hidden -Wdeclaration-after-statement -Werror=declaration-after-statement -D_REENTRANT -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/var/tmp/portage/media-libs/libsdl2-2.0.14-r1/work/SDL2-2.0.14-.arm64/src/hidapi/hidapi -D_REENTRANT -DHAVE_LINUX_VERSION_H -MMD -MT build/SDL_test_random.lo -c /var/tmp/portage/media-libs/libsdl2-2.0.14-r1/work/SDL2-2.0.14-.arm64/src/test/SDL_test_random.c  -fPIC -DPIC -o build/.libs/SDL_test_random.o

Note the -I/opt/vc/* references, which are not present when vc4 is unset

Using the latest raspberry-userland (0_pre20201022), these folders are empty.
Comment 15 Skyler Mäntysaari 2021-03-04 18:44:16 UTC
What's the current situation on getting the patch upstreamed?
Comment 16 pavouk106 2021-03-07 21:11:15 UTC
(In reply to Guillaume Lespinasse from comment #14)
> When vc4 is set however, libsdl2 seems to be trying to access a now unused
> set of folders...
> 
> Note the -I/opt/vc/* references, which are not present when vc4 is unset

I have tried to make symlink to actual location (ln -s /usr /opt/vc) but the errors are the same "undefined reference to `vc_dispmanx..." when linking.

I don't know how linking works so I can only think the linker doesn't see the files even when linked to their actual location. I don't know what to try next.

And libsdl2-2.0.12 (the only one working as comment 11 stated) is not in portage anymore
Comment 17 Murilo Morais 2021-05-30 14:43:49 UTC
After removing the "raspberrypi-userland" package, compilation and linking took place normally without the patch. Since I am new to Raspberry PI I cannot say how influential this package is.
Comment 18 Bram Verweij 2021-05-31 21:04:12 UTC
Adding -video_cards_vc4 to the use flags for media-libs/libsdl2 also makes it compile just fine without any patch.

raspberrypi-userland is quite useful on a raspberry pi, you wouldn't want to remove that. However, on arm64 you get a stripped-down version of it. (See also https://github.com/raspberrypi/userland#readme.)

The video_cards_vc4 use flag passes --enable-video-rpi to the configure script of libsdl2. Then libsdl2 expects to find the libs from the 32-bit raspberry pi userland. To my understanding these correspond to the old closed-source binary broadcom drivers (which are not supported on arm64). 

Please note that VC4 is the modern open-source kernel/mesa driver. In that respect, the video_cards_vc4 use flag seems to be abused in the context of the libsdl2 ebuild (since it forces linking to the old closed-source binary broadcom drivers).

The SDL video driver actually seems to work for me on a RPi4 (aarch64, gbm/kms) after compiling libsdl2 without video_cards_vc4. (Tested with retroarch.)
Comment 19 Bradley Jarvis 2021-08-06 09:59:31 UTC
Created attachment 730813 [details, diff]
fix linking libvchostif library

Not sure if this is the best place to put it but I added -lvchostif to configure.ac . I did it by updating libsdl2-2.0.14-static-libs.patch in the libsdl files. For me I could probably get rid of the library paths '-Wl,-rpath,/opt/vc/lib -L/opt/vc/lib' too because in my install they didn't exist anyway. I did try creating a symlink from /usr/lib64/libvchostif.so to /opt/vc/lib/libvchostif.so but didn't work.
Comment 20 Bradley Jarvis 2021-08-06 10:02:00 UTC
This allows me to compile libsdl with vc4 support for rpi4 arm64, the compilation and install is successful but have not tested yet, waiting for the rest of emerge world to finish and upto webkit-gtk
Comment 21 Ivan S. Titov 2021-08-08 14:01:20 UTC
(In reply to Bradley Jarvis from comment #19)
> Created attachment 730813 [details, diff] [details, diff]
> fix linking libvchostif library
> 
> Not sure if this is the best place to put it but I added -lvchostif to
> configure.ac . I did it by updating libsdl2-2.0.14-static-libs.patch in the
> libsdl files. For me I could probably get rid of the library paths
> '-Wl,-rpath,/opt/vc/lib -L/opt/vc/lib' too because in my install they didn't
> exist anyway. I did try creating a symlink from /usr/lib64/libvchostif.so to
> /opt/vc/lib/libvchostif.so but didn't work.

What are the USE-flags do you use?
My build with your patch fails with 

make: *** [Makefile:545: build/SDL_egl.lo] Error 1


I have USE="X alsa dbus gles1 gles2 joystick kms opengl pulseaudio sound threads udev video wayland xscreensaver"
Comment 22 Bradley Jarvis 2021-08-08 14:30:29 UTC
[ebuild   R    ] media-libs/libsdl2-2.0.14-r2::local  USE="X alsa dbus gles1 gles2 joystick opengl pulseaudio sound threads udev video vulkan wayland (-aqua) (-custom-cflags) -fcitx4 -haptic -ibus -jack -kms -libsamplerate -nas -oss -sndio -static-libs -xinerama -xscreensaver" VIDEO_CARDS="vc4" 0 KiB

Do you have the file libvchostif.so? for me it is in /usr/lib64 and is installed from media-libs/raspberrypi-userland. I used the ebuild from the standard gentoo repository
Comment 23 Bradley Jarvis 2021-08-08 14:34:41 UTC
Actually just looking in the ebuild and it should probably include the line

video_cards_vc4? (media-libs/raspberrypi-userland)

in CDEPEND to install libvchostif.so
Comment 24 Ivan S. Titov 2021-08-08 15:10:04 UTC
(In reply to Bradley Jarvis from comment #23)
> Actually just looking in the ebuild and it should probably include the line
> 
> video_cards_vc4? (media-libs/raspberrypi-userland)
 That's a really good idea! 
> in CDEPEND to install libvchostif.so


Well, my bad, didn't include first patch posted here, 'vc4_f_ok.patch'.
Now everything builds, and seemingly works.
So I can confirm that this 'fix linking libvchostif library' patch works too.
Comment 25 Ivan S. Titov 2021-08-11 23:50:11 UTC
Created attachment 732340 [details, diff]
libsdl2 updated ebuild

Checked the newly bumped 2.0.16 version, everything builds with slight changes.
I keyworded the ebuild only to ~arm and ~arm64, dependency video_cards_vc4? (media-libs/raspberrypi-userland).
Comment 26 Ivan S. Titov 2021-08-11 23:50:42 UTC
Created attachment 732343 [details, diff]
consolidated patch.

... and consolidated the patch into a single one.
Comment 27 Tee KOBAYASHI 2021-11-18 07:37:52 UTC
Created attachment 752310 [details, diff]
User patch for libsdl2-2.0.16-r1

See also https://bugs.gentoo.org/824270
Comment 28 7e3 2022-03-12 04:11:38 UTC
Are we really at the bottom of this duo (with bug #824270)?

I also had a few attempts to get 2.0.12-r1 working (the same that hangglider  on in comment 2).

I was stuck with Bug #824270, and had seen this bug progress but thought I'd try "~arm64" giving 2.0.20-r1 and that seems to work (did something get upstreamed already?).

It did not *seem* to correlate to anything to do with v3d or vc4 as I had both...
BUT...
Interestingly I was recently playing with the mesa problem from a couple of years ago where sakaki had to manually put v3d in for Raspberry Pi 4 to force gallium for mesa (sorry I'm new so cannot post the link).

Soooo maybe there is something not being picked up in another package somewhere?..
I've not yet looked into why 2.0.20-r1 fixed 824270 though.