Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built static link libraries are stripped of debuginfo #247

Open
Conan-Kudo opened this issue Jan 12, 2025 · 19 comments
Open

Built static link libraries are stripped of debuginfo #247

Conan-Kudo opened this issue Jan 12, 2025 · 19 comments

Comments

@Conan-Kudo
Copy link

When building sdl2-compat in Fedora, rpmlint notes that the static link libraries are missing debuginfo:

sdl2-compat-devel.aarch64: E: static-library-without-debuginfo /usr/lib64/libSDL2_test.a
sdl2-compat-devel.aarch64: E: static-library-without-debuginfo /usr/lib64/libSDL2main.a
sdl2-compat-static.aarch64: E: static-library-without-debuginfo /usr/lib64/libSDL2.a

I'm not sure what's doing this as I'm not doing it.

@madebr
Copy link
Contributor

madebr commented Jan 12, 2025

Can you share verbose build logs?

@Conan-Kudo
Copy link
Author

@madebr
Copy link
Contributor

madebr commented Jan 13, 2025

What heuristic is used to detect presence of debuginfo?
grepping for SDL2-static in the log shows the static sources are compiled with -g -flto=auto and additional flags

@Conan-Kudo
Copy link
Author

Conan-Kudo commented Jan 13, 2025

@madebr
Copy link
Contributor

madebr commented Jan 13, 2025

I can't reproduce this.
I copied some of your CFLAGS, and ran objdump -h on the object files, which shows multiple .debug_* section headers.

cmake .. -DSDL2COMPAT_STATIC=ON -DCMAKE_C_FLAGS="-O2 -flto=auto -ffat-lto-objects -fexceptions -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong  -Wdeclaration-after-statement -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja SDL2-static
mkdir -p objects
ar --output=objects x libSDL2.a
objdump -h objects/SDL_dynapi.c.o | grep debug_
objdump -h objects/sdl2_compat.c.o | grep debug_

@madebr
Copy link
Contributor

madebr commented Jan 13, 2025

Side question: Does Fedora build their static libraries with lto enabled?

@Conan-Kudo
Copy link
Author

Yes it does. LTO is enabled for everything by default.

@slouken
Copy link
Collaborator

slouken commented Jan 13, 2025

rpmlint validates that .debug_* sections exist in the archive:

https://github.com/rpm-software-management/rpmlint/blob/a0b90cf97a93cc3182fc1d58e889251e780d14c6/rpmlint/checks/BinariesCheck.py#L288-L294

If that's the case, doesn't that mean everything is okay?

@Conan-Kudo
Copy link
Author

My RPM builds seem to indicate no debuginfo?

ngompa@fedora ~/r/s/R/u/lib64> objdump -h objects/SDL_dynapi.c.o

objects/SDL_dynapi.c.o:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00012f49  0000000000000000  0000000000000000  00000040  2**5
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  0000000000000000  0000000000000000  00012f89  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000008  0000000000000000  0000000000000000  00012f89  2**2
                  ALLOC
  3 .annobin.notes 0000019f  0000000000000000  0000000000000000  00012f89  2**0
                  CONTENTS, READONLY
  4 .rodata.str1.1 00000047  0000000000000000  0000000000000000  00013128  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .rodata.str1.8 0000017f  0000000000000000  0000000000000000  0001316f  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .data.rel.local 00001a30  0000000000000000  0000000000000000  000132ee  2**5
                  CONTENTS, ALLOC, LOAD, RELOC, DATA
  7 .comment      0000002f  0000000000000000  0000000000000000  00014d1e  2**0
                  CONTENTS, READONLY
  8 .note.GNU-stack 00000000  0000000000000000  0000000000000000  00014d4d  2**0
                  CONTENTS, READONLY
  9 .note.gnu.property 00000050  0000000000000000  0000000000000000  00014d4d  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 10 .eh_frame     0000b640  0000000000000000  0000000000000000  00014d9d  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
ngompa@fedora ~/r/s/R/u/lib64> objdump -h objects/sdl2_compat.c.o

objects/sdl2_compat.c.o:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         0001380a  0000000000000000  0000000000000000  00000040  2**5
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000004  0000000000000000  0000000000000000  0001384a  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00002a00  0000000000000000  0000000000000000  0001384e  2**5
                  ALLOC
  3 .annobin.notes 00000193  0000000000000000  0000000000000000  0001384e  2**0
                  CONTENTS, READONLY
  4 .text.startup 000047ef  0000000000000000  0000000000000000  000139e1  2**6
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  5 .rodata.str1.1 00004654  0000000000000000  0000000000000000  000181d0  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .rodata.str1.8 00001155  0000000000000000  0000000000000000  0001c824  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .init_array   00000008  0000000000000000  0000000000000000  0001d979  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, DATA
  8 .text.exit    00000009  0000000000000000  0000000000000000  0001d981  2**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  9 .fini_array   00000008  0000000000000000  0000000000000000  0001d98a  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, DATA
 10 .rodata       00000158  0000000000000000  0000000000000000  0001d992  2**5
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
 11 .data.rel.ro.local 00000280  0000000000000000  0000000000000000  0001daea  2**5
                  CONTENTS, ALLOC, LOAD, RELOC, DATA
 12 .rodata.cst4  00000028  0000000000000000  0000000000000000  0001dd6a  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 13 .rodata.cst16 00000050  0000000000000000  0000000000000000  0001dd92  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 14 .rodata.cst8  00000070  0000000000000000  0000000000000000  0001dde2  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 15 .comment      0000002f  0000000000000000  0000000000000000  0001de52  2**0
                  CONTENTS, READONLY
 16 .note.GNU-stack 00000000  0000000000000000  0000000000000000  0001de81  2**0
                  CONTENTS, READONLY
 17 .note.gnu.property 00000050  0000000000000000  0000000000000000  0001de81  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 18 .eh_frame     00006718  0000000000000000  0000000000000000  0001ded1  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA

@madebr
Copy link
Contributor

madebr commented Jan 13, 2025

Same with these?

objdump -h CMakeFiles/SDL2-static.dir/src/sdl2_compat.c.o  | grep debug
objdump -h CMakeFiles/SDL2-static.dir/src/dynapi/SDL_dynapi.c.o | grep debug

I don't get it, because you're passing -g:

/usr/bin/gcc -DSDL2COMPAT_REVISION=\"SDL-2.30.50-g733e1ad\" -D_REENTRANT  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer  -Wall -fvisibility=hidden -Wdeclaration-after-statement -Wall -Wundef -Wshadow -Wno-unused-local-typedefs -fdiagnostics-color=always -MD -MT CMakeFiles/SDL2-static.dir/src/sdl2_compat.c.o -MF CMakeFiles/SDL2-static.dir/src/sdl2_compat.c.o.d -o CMakeFiles/SDL2-static.dir/src/sdl2_compat.c.o -c /builddir/build/BUILD/sdl2-compat-2.30.50_git20250107.c368587-build/sdl2-compat-c368587979b4c69b79f864f3ff7a2c53a71644c9/src/sdl2_compat.c
/usr/bin/gcc -DSDL2COMPAT_REVISION=\"SDL-2.30.50-g733e1ad\" -D_REENTRANT  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer  -Wall -fvisibility=hidden -Wdeclaration-after-statement -Wall -Wundef -Wshadow -Wno-unused-local-typedefs -fdiagnostics-color=always -MD -MT CMakeFiles/SDL2-static.dir/src/dynapi/SDL_dynapi.c.o -MF CMakeFiles/SDL2-static.dir/src/dynapi/SDL_dynapi.c.o.d -o CMakeFiles/SDL2-static.dir/src/dynapi/SDL_dynapi.c.o -c /builddir/build/BUILD/sdl2-compat-2.30.50_git20250107.c368587-build/sdl2-compat-c368587979b4c69b79f864f3ff7a2c53a71644c9/src/dynapi/SDL_dynapi.c
/usr/bin/ar qc libSDL2.a "CMakeFiles/SDL2-static.dir/src/sdl2_compat.c.o" "CMakeFiles/SDL2-static.dir/src/dynapi/SDL_dynapi.c.o"

Perhaps the spec files are doing things?
Can you remove arguments until debug sections start to appear?

I don't think we're doing special things in the CMake script.

@Conan-Kudo
Copy link
Author

This is what the build phase of the spec file does:

  CFLAGS="${CFLAGS:--O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer }" ; export CFLAGS ;
  CXXFLAGS="${CXXFLAGS:--O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer }" ; export CXXFLAGS ;
  FFLAGS="${FFLAGS:--O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/lib64/gfortran/modules }" ; export FFLAGS ;
  FCFLAGS="${FCFLAGS:--O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/lib64/gfortran/modules }" ; export FCFLAGS ;
  VALAFLAGS="${VALAFLAGS:--g}" ; export VALAFLAGS ;
  RUSTFLAGS="${RUSTFLAGS:--Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cstrip=none -Cforce-frame-pointers=yes -Clink-arg=-specs=/usr/lib/rpm/redhat/redhat-package-notes --cap-lints=warn}" ; export RUSTFLAGS ;
  LDFLAGS="${LDFLAGS:--Wl,-z,relro -Wl,--as-needed  -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes }" ; export LDFLAGS ;
  LT_SYS_LIBRARY_PATH="${LT_SYS_LIBRARY_PATH:-/usr/lib64:}" ; export LT_SYS_LIBRARY_PATH ;
  CC="${CC:-gcc}" ; export CC ;
  CXX="${CXX:-g++}" ; export CXX
  /usr/bin/cmake \
        -S "." \
        -B "redhat-linux-build" \
        -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
        -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF \
        -DCMAKE_INSTALL_PREFIX:PATH=/usr \
        -DINCLUDE_INSTALL_DIR:PATH=/usr/include \
        -DLIB_INSTALL_DIR:PATH=/usr/lib64 \
        -DSYSCONF_INSTALL_DIR:PATH=/etc \
        -DSHARE_INSTALL_PREFIX:PATH=/usr/share \
        -DLIB_SUFFIX=64 \
        -DBUILD_SHARED_LIBS:BOOL=ON -DSDL2COMPAT_STATIC=ON

  /usr/bin/cmake --build "redhat-linux-build" -j${RPM_BUILD_NCPUS} --verbose

@slouken
Copy link
Collaborator

slouken commented Jan 13, 2025

As an aside, can we not build a static SDL library? It's actually pretty valuable to be able to upgrade SDL and have installed applications pick up the fixes.

@Conan-Kudo
Copy link
Author

Conan-Kudo commented Jan 13, 2025

IIRC, even static SDL will load dynamic SDL if available, but... sure? I'm really only building it because the old SDL2 package had them...

@Conan-Kudo
Copy link
Author

It seems like the stuff built by CMake has them...

<mock-chroot> sh-5.2# objdump -h CMakeFiles/SDL2-static.dir/src/sdl2_compat.c.o  | grep debug
objdump -h CMakeFiles/SDL2-static.dir/src/dynapi/SDL_dynapi.c.o | grep debug
  4 .gnu.debuglto_.debug_info 0001a912  0000000000000000  0000000000000000  000139e1  2**0
  5 .gnu.debuglto_.debug_abbrev 000004bb  0000000000000000  0000000000000000  0002e2f3  2**0
  6 .gnu.debuglto_.debug_line 0000016b  0000000000000000  0000000000000000  0002e7ae  2**0
  7 .gnu.debuglto_.debug_str 00017178  0000000000000000  0000000000000000  0002e919  2**0
  8 .gnu.debuglto_.debug_line_str 000004d4  0000000000000000  0000000000000000  00045a91  2**0
1037 .debug_info   0003c354  0000000000000000  0000000000000000  0014861c  2**0
1038 .debug_abbrev 00000b7a  0000000000000000  0000000000000000  00184970  2**0
1039 .debug_loclists 00017d2d  0000000000000000  0000000000000000  001854ea  2**0
1040 .debug_aranges 00000090  0000000000000000  0000000000000000  0019d217  2**0
1041 .debug_rnglists 00001784  0000000000000000  0000000000000000  0019d2a7  2**0
1042 .debug_line   00011393  0000000000000000  0000000000000000  0019ea2b  2**0
1043 .debug_str    00017189  0000000000000000  0000000000000000  001afdbe  2**0
1044 .debug_line_str 0000056e  0000000000000000  0000000000000000  001c6f47  2**0
  4 .gnu.debuglto_.debug_info 00021fc0  0000000000000000  0000000000000000  00013128  2**0
  5 .gnu.debuglto_.debug_abbrev 00000569  0000000000000000  0000000000000000  000350e8  2**0
  6 .gnu.debuglto_.debug_line 00000147  0000000000000000  0000000000000000  00035651  2**0
  7 .gnu.debuglto_.debug_str 0001cc4d  0000000000000000  0000000000000000  00035798  2**0
  8 .gnu.debuglto_.debug_line_str 0000050c  0000000000000000  0000000000000000  000523e5  2**0
1709 .debug_info   0003a1e7  0000000000000000  0000000000000000  00154c5f  2**0
1710 .debug_abbrev 00000819  0000000000000000  0000000000000000  0018ee46  2**0
1711 .debug_loclists 0001a8f6  0000000000000000  0000000000000000  0018f65f  2**0
1712 .debug_aranges 00000030  0000000000000000  0000000000000000  001a9f55  2**0
1713 .debug_rnglists 0000006b  0000000000000000  0000000000000000  001a9f85  2**0
1714 .debug_line   0000b97a  0000000000000000  0000000000000000  001a9ff0  2**0
1715 .debug_str    0001cc5e  0000000000000000  0000000000000000  001b596a  2**0
1716 .debug_line_str 000005a5  0000000000000000  0000000000000000  001d25c8  2**0

@Conan-Kudo
Copy link
Author

Conan-Kudo commented Jan 13, 2025

As an aside, can we not build a static SDL library? It's actually pretty valuable to be able to upgrade SDL and have installed applications pick up the fixes.

Note that even if we have static sdl2-compat, it's still using dynamic SDL3, and we definitely don't recommend or use static SDL for Fedora-built SDL applications.

@madebr
Copy link
Contributor

madebr commented Jan 13, 2025

Your log contains the following line:

+ /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip

What does that do?

@Conan-Kudo
Copy link
Author

@madebr
Copy link
Contributor

madebr commented Jan 13, 2025

That script is causing the mischief.

In a local build directory, I ran these commands and confirmed a .debug_* sections exist.

Then I downloaded brp-strip-static-archive, and executed the following in the build directory:

RPM_BUILD_ROOT=$PWD ./brp-strip-static-archive  /usr/bin/strip

When running the ar and objdump steps again, the debug sections disappeared.

Running ls -al libSDL2.a before and after running the command show a decrease in filesize:

#before:
-rw-r--r--. 1 maarten maarten 5810274 Jan 13 05:50 libSDL2.a
#after
-rw-r--r--. 1 maarten maarten 3034938 Jan 13 05:50 libSDL2.a

Running the following, it shows that it runs strip on every static library:

$ STRIP=echo RPM_BUILD_ROOT=$PWD ./brp-strip-static-archive
-g ./libSDL2.a

@Conan-Kudo
Copy link
Author

@pmatilai, is this what this script is supposed to do? I thought rpm is supposed to do split debuginfo for this, not delete them entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants