How to build kernel debug info as separate file? - linux

When we share custom built kernel, It is common to give without debug info.
Similar to sudo apt-get install linux-image-$(uname -r)-dbgsym, I would like to create separate debug info file for custom built kernel.
Here and here they explained generally. I request to share knowledge on creating separate debug info file for entire linux kernel.
For sample program
$ gcc -g calc.c
$ ls -l
total 16
-rwxrwxr-x 1 jeyaram jeyaram 8424 Apr 8 09:44 a.out
-rw-rw-r-- 1 jeyaram jeyaram 246 Apr 8 09:32 calc.c
$ objcopy --only-keep-debug a.out a.debug
$ gcc calc.c -------------> compiling without debug info (skipped 'strip')
$ ls -l
total 20
-rwxrwxr-x 1 jeyaram jeyaram 4736 Apr 8 09:45 a.debug
-rwxrwxr-x 1 jeyaram jeyaram 7200 Apr 8 09:52 a.out
-rw-rw-r-- 1 jeyaram jeyaram 246 Apr 8 09:32 calc.c
$ objcopy --add-gnu-debuglink=a.debug a.out
$ gdb a.out
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/jeyaram/JJJ/debug_info_analysis/sample_c_test/a.out...Reading symbols from /home/jeyaram/JJJ/debug_info_analysis/sample_c_test/a.debug...done.
done.
But while trying with vmlinux
$ objcopy --only-keep-debug vmlinux vmlinux.debug
objcopy: Unable to recognise the format of the input file `vmlinux'
Missing something ???

vmlinux is a binary blob. The file you're looking for is vmlinux.bin (which is the elf intermediate).
Works like charm:
objcopy --only-keep-debug vmlinux.bin vmlinux.debug

arm-linux-gnueabi-objcopy --only-keep-debug vmlinux vmlinux.debug will works fine.
$ ls -l vmlinux*
-rwxrwxr-x 1 jeyaram jeyaram 7871108 Apr 8 11:24 vmlinux
-rwxrwxr-x 1 jeyaram jeyaram 92520922 Apr 8 11:21 vmlinux.debug
-rw-rw-r-- 1 jeyaram jeyaram 162974220 Apr 7 14:16 vmlinux.o

Related

S-record files output by objcopy are smaller than the original binaries

After using arm-none-eabi-gcc to build a file in ELF format, I am using arm-none-eabi-objcopy to create an S-record file. The command that my makefile runs is:
$(TOOLCHAIN)-objcopy --srec-len 10 -O srec "$<" "$#"
The makefile can build with various different settings - with debug symbols, with optimization, and with neither.
With some information such as my username removed, the output of ls -la after doing all three builds is:
-rw-r--r-- 1 4096 270330 Oct 12 18:13 outfile_Debug.mot
-rw-r--r-- 1 4096 825888 Oct 12 18:13 outfile_Debug.out
-rw-r--r-- 1 4096 270334 Oct 12 17:06 outfile_Default.mot
-rw-r--r-- 1 4096 465928 Oct 12 17:06 outfile_Default.out
-rw-r--r-- 1 4096 184776 Oct 12 19:02 outfile_Optimized.mot
-rw-r--r-- 1 4096 395672 Oct 12 19:02 outfile_Optimized.out
Now, I have read an unsourced claim that srec files canot contain debugging information, which would explain why the Default and Debug .mot files are roughly the same size while the corresponding .out file sizes differ enormously. But otherwise, the ELF file is a binary representation of the executable, while the S-record file uses hex strings in ASCII text, so surely it should be larger than the binary ELF file for a non-debug build?

configure: error: --with-ssl was given, but OpenSSL wasn't found on ubuntu 20.04?

I have try to compile and build libcurl inside my toolcahin folder by using cross compile but always I got same error...
1-First I build openssl by this steps
export TOOLCHAIN=/home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi
export CC=$TOOLCHAIN/bin/arm-linux-gnueabi-gcc-7.5.0
export RANLIB=$TOOLCHAIN/bin/arm-linux-gnueabi-ranlib
export PATH="$TOOLCHAIN/bin:$PATH"
./Configure linux-generic32 --prefix=$TOOLCHAIN/arm-linux-gnueabi/libc/usr no-async
make depends
make
make install
.
.
.
cp libcrypto.pc /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/sysroot/usr/lib/pkgconfig
chmod 644 /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/sysroot/usr/lib/pkgconfig/libcrypto.pc
cp libssl.pc /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/sysroot/usr/lib/pkgconfig
chmod 644 /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/sysroot/usr/lib/pkgconfig/libssl.pc
cp openssl.pc /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/sysroot/usr/lib/pkgconfig
chmod 644 /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/sysroot/usr/lib/pkgconfig/openssl.pc
.
.
.
~/$ ls -n from gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi
total 36
drwxr-xr-x 6 raed raed 4096 نوف 26 12:31 arm-linux-gnueabi
drwxr-xr-x 2 raed raed 4096 ديس 4 2019 bin
-rw-r--r-- 1 raed raed 11287 ديس 4 2019 gcc-linaro-7.5.0-2019.12-linux-manifest.txt
drwxr-xr-x 3 raed raed 4096 ديس 4 2019 include
drwxr-xr-x 3 raed raed 4096 ديس 4 2019 lib
drwxr-xr-x 3 raed raed 4096 ديس 4 2019 libexec
drwxr-xr-x 8 raed raed 4096 ديس 4 2019 share
~/$ ls -n from arm-linux-gnueabi/libc/usr
total 28
drwxr-xr-x 2 raed raed 4096 نوف 26 12:18 bin
drwxr-xr-x 34 raed raed 4096 نوف 26 12:18 include
drwxr-xr-x 6 raed raed 4096 نوف 26 12:18 lib
drwxr-xr-x 3 raed raed 4096 ديس 4 2019 libexec
drwxr-xr-x 2 raed raed 4096 ديس 4 2019 sbin
drwxr-xr-x 5 raed raed 4096 ديس 4 2019 share
drwxrwxr-x 6 raed raed 4096 نوف 26 12:18 ssl
2-Then I have try to build libcurl with--ssl but I have got error
cd curl-7.72.0
export TOOLCHAIN=/home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi
export CC=$TOOLCHAIN/bin/arm-linux-gnueabi-gcc-7.5.0
export RANLIB=$TOOLCHAIN/bin/arm-linux-gnueabi-ranlib
export PATH="$TOOLCHAIN/bin:$PATH"
./configure --with-ssl=/home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/usr --host=arm-linux-gnueabi
.
.
.
configure: PKG_CONFIG_LIBDIR will be set to "/home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/usr/lib/pkgconfig"
checking for arm-linux-gnueabi-pkg-config... /usr/bin/pkg-config
checking for openssl options with pkg-config... found
configure: pkg-config: SSL_LIBS: "-lssl -lcrypto"
configure: pkg-config: SSL_LDFLAGS: "-L/home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/usr/lib"
configure: pkg-config: SSL_CPPFLAGS: "-I/home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/usr/include"
checking for HMAC_Update in -lcrypto... no
checking for HMAC_Init_ex in -lcrypto... no
checking OpenSSL linking with -ldl... no
checking OpenSSL linking with -ldl and -lpthread... no
configure: OPT_SSL: /home/MY/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/usr
configure: OPENSSL_ENABLED:
configure: error: --with-ssl was given but OpenSSL could not be detected
P.s: same steps work just fine on ubuntu 18.04
There are a lot of different ways to build libcurl with openssl support, and this may not be immediate to find out what is causing this issue.
But here is the procedure I am using on Ubuntu 20.04.1 - You may have to adjust the content of the CROSS_COMPILE variable, since you are using the arm-linux-gnueabi toolchain, and not the arm-none-linux-gnueabihf one: I am using the gcc toolchain for Cortex-A from ARM.
The versions of curl and openssl may have to be adjusted as well.
CROSS_COMPILE=/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-
PREFIX=$(pwd)/sysroot
wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
tar zxf openssl-1.1.1h.tar.gz
pushd openssl-1.1.1h
./Configure linux-generic32 shared -DL_ENDIAN --prefix=${PREFIX} --openssldir=${PREFIX} shared
make CROSS_COMPILE=/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf- PROCESSOR=ARM install
popd
wget https://zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
pushd zlib-1.2.11
CC=${CROSS_COMPILE}gcc ./configure --prefix=${PREFIX}
make CC=${CROSS_COMPILE}gcc all install
popd
wget https://curl.haxx.se/download/curl-7.73.0.tar.gz
tar zxf curl-7.73.0.tar.gz
pushd curl-7.73.0
CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld AR=${CROSS_COMPILE}ar NM=${CROSS_COMPILE}nm AS=${CROSS_COMPILE}as ./configure --disable-static --enable-shared --with-ssl=${PREFIX} --prefix=${PREFIX} --host=arm-none-linux-gnueabihf --target=arm-none-linux-gnueabihf --without-libidn2
make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld AR=${CROSS_COMPILE}ar NM=${CROSS_COMPILE}nm AS=${CROSS_COMPILE}as install
popd
ll -gG sysroot/lib/
total 6796
drwxrwxr-x 4 4096 Nov 16 08:10 ./
drwxrwxr-x 9 4096 Nov 16 07:53 ../
drwxrwxr-x 2 4096 Nov 16 07:53 engines-1.1/
-rw-r--r-- 1 3199974 Nov 16 07:53 libcrypto.a
lrwxrwxrwx 1 16 Nov 16 07:53 libcrypto.so -> libcrypto.so.1.1*
-rwxr-xr-x 1 2087864 Nov 26 07:53 libcrypto.so.1.1*
-rwxr-xr-x 1 1027 Nov 26 08:10 libcurl.la*
lrwxrwxrwx 1 16 Nov 26 08:10 libcurl.so -> libcurl.so.4.7.0*
lrwxrwxrwx 1 16 Nov 26 08:10 libcurl.so.4 -> libcurl.so.4.7.0*
-rwxr-xr-x 1 407748 Nov 26 08:10 libcurl.so.4.7.0*
-rw-r--r-- 1 578076 Nov 26 07:53 libssl.a
lrwxrwxrwx 1 13 Nov 26 07:53 libssl.so -> libssl.so.1.1*
-rwxr-xr-x 1 453684 Nov 26 07:53 libssl.so.1.1*
-rw-r--r-- 1 96210 Nov 26 07:51 libz.a
lrwxrwxrwx 1 14 Nov 26 07:51 libz.so -> libz.so.1.2.11*
lrwxrwxrwx 1 14 Nov 26 07:51 libz.so.1 -> libz.so.1.2.11*
-rwxr-xr-x 1 98708 Nov 26 07:51 libz.so.1.2.11*
drwxrwxr-x 2 4096 Nov 26 08:10 pkgconfig/
file sysroot/bin/curl
sysroot/bin/curl: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, with debug_info, not stripped
share edit delete flag
Thank you ..
I solve the issue ...
The problem is with zlib need to build it inside toolchain and add this in configure seetings
--with-zlib=$prefix/lib

Cannot open shared object file libpng12.so.0

I am trying to run Quartus 13.0 in the following machine:
parrot 4.18.0-parrot10-amd64 #1 SMP Debian 4.18.10-1parrot10 (2018-10-06) x86_64 GNU/Linux.
I have finished installing Quartus 13.0 and when I try to execute it I get this error:
quartus: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory
I have read all the related questions in stack overflow and other websites but no one worked for me.
When looking for that file, I found it. I have tried to do a hard link but it doesn't work either. Search results:
┌─[pepbd#parrot]─[~]
└──╼ $ls -ld $(locate -r libpng.*\.so.*)
lrwxrwxrwx 1 root root 19 nov 19 17:09 /usr/lib/x86_64-linux-gnu/libpng16.so.16 -> libpng16.so.16.34.0
-rw-r--r-- 1 root root 210864 jul 10 13:17 /usr/lib/x86_64-linux-gnu/libpng16.so.16.34.0
-rw-r--r-- 1 root root 18272 oct 14 21:59 /usr/lib/x86_64-linux-gnu/vlc/plugins/codec/libpng_plugin.so
I had the same problem with Quartus Prime 18 on Ubuntu. This worked for me (run as sudo):
wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
&& dpkg -i /tmp/libpng12.deb \
&& rm /tmp/libpng12.deb

No such file or directory when running sublime text 3

I need some help installing sublime text 3 in Nixos 17.03.
I have downloaded and unpacked the tar ball from sublime and this it was happens when I try to execute /opt/sublime_text/sublime_text:
/opt/sublime_text/sublime_text
sh: /opt/sublime_text/sublime_text: No such file or directory
The file exist in the correct location with run permissions.
sh-4.4$ cd /opt/sublime_text/
sh-4.4$ ls -la
totalt 15944
drwxr-xr-x 4 jan users 4096 23 sep 2016 .
drwxr-xr-x 7 jan users 4096 30 apr 23.28 ..
-rw-r--r-- 1 jan users 30118 23 sep 2016 changelog.txt
-rwxr-xr-x 1 jan users 488672 23 sep 2016 crash_reporter
drwxr-xr-x 7 jan users 4096 23 sep 2016 Icon
drwxr-xr-x 2 jan users 4096 23 sep 2016 Packages
-rwxr-xr-x 1 jan users 7883616 23 sep 2016 plugin_host
-rw-r--r-- 1 jan users 2624408 23 sep 2016 python3.3.zip
-rw-r--r-- 1 jan users 28578 23 sep 2016 sublime_plugin.py
-rw-r--r-- 1 jan users 37137 23 sep 2016 sublime.py
-rwxr-xr-x 1 jan users 5200392 23 sep 2016 sublime_text
-rw-r--r-- 1 jan users 532 23 sep 2016 sublime_text.desktop
Yes, the file does exist there and is executable! But, the error message is misleading.
Try to run file command on that ELF file:
$ file ./sublime_text
./sublime_text: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=e359d67c8f71f88174135aefc069239f64f26c42, stripped
You see, it refers to /lib/ld-linux.so.2 interpreter library, which doesn't exist on NixOS.
Though sublimetext3 is packaged in Nixpkgs, and we can see that it refers to another interpreter:
$ file /nix/store/bv5j4qiif1h9db6qcfl9axhv7rvza2b8-sublimetext3-3114-bin/.sublime_text-wrapped
/nix/store/bv5j4qiif1h9db6qcfl9axhv7rvza2b8-sublimetext3-3114-bin/.sublime_text-wrapped: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/jm1n87rp8vr90j9ahcrfzr57nc2r8vgf-glibc-2.24/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=93b181f0f699bd88a052048070efe8ad6757a6fd, stripped
This is achieved by running patchelf on the binary, which is a common trick in Nixpkgs/NixOS to fix binaries.

How can you determine installed versions of the glibc libraries?

I'm working with an embedded Linux deployment and am using a cross compiler tool chain that doesn't compile I2C library function calls.
How do I determine the precise versions of the libraries on the system so that I may rebuild the tool chain?
I don't intend to replace the libraries deployed, as I do know they work (including I2C), so I believe I need the following:
Binutils version
GCC version
GLIBC
Kernel (for the headers)
I think I can assume from the following that the binutils library is version 2.2.5. The kernel is modded for which I've the source.
root#dev-box />ls /lib/ -al
drwxrwxrwx 3 root root 1024 Apr 27 09:44 .
drwxrwxrwx 14 root root 1024 Jan 1 1970 ..
-rwxrwxrwx 1 root root 105379 Jan 1 1970 ld-2.2.5.so
lrwxrwxrwx 1 root root 16 Jan 1 1970 ld-linux.so.2 -> /lib/ld-2.2.5.so
lrwxrwxrwx 1 root root 16 Jan 1 1970 ld.so.1 -> /lib/ld-2.2.5.so
-rwxrwxrwx 1 root root 1288601 Jan 1 1970 libc.so.6
-rwxrwxrwx 1 root root 25441 Jan 1 1970 libcrypt.so.1
-rwxrwxrwx 1 root root 14303 Jan 1 1970 libdl.so.2
-rwxrwxrwx 1 root root 36800 Jan 1 1970 libgcc_s.so.1
-rwxrwxrwx 1 root root 530401 Jan 1 1970 libm.so.6
-rwxrwxrwx 1 root root 86626 Jan 1 1970 libnsl.so.1
-rwxrwxrwx 1 root root 17533 Jan 1 1970 libnss_dns.so.2
-rwxrwxrwx 1 root root 46324 Jan 1 1970 libnss_files.so.2
-rwxrwxrwx 1 root root 98633 Jan 1 1970 libpthread.so.0
-rwxrwxrwx 1 root root 69966 Jan 1 1970 libresolv.so.2
-rwxrwxrwx 1 root root 12897 Jan 1 1970 libutil.so.1
For glibc:
/lib/libc.so.6
Sounds maybe strange to run a so file but should print out version information in this case
For the kernel version use uname
For the binutils parsing the output of ld --versionmight yield what you expect, the same for gcc --version. This is a bit tedious but I do not know another way.
a more comprehensive answer can be found by running
find /lib -iname 'libc*.so'
On a recent system this will give you results like this that show i'm using glibc 2.28 here on ubuntu 18.10
/lib/x86_64-linux-gnu/libc-2.28.so
/lib/x86_64-linux-gnu/libcrypt-2.28.so
/lib/i386-linux-gnu/libc-2.28.so
/lib/i386-linux-gnu/libcrypt-2.28.so
For multiarch system you can have multiple copies for 386 and 64 modes , i think these should be the same .
i didn't have a /lib/libc.so.* on my system.
To know the current installed version of glibc, please compile and run the following C code.
#include <stdio.h>
#include <gnu/libc-version.h>
int main (void) { puts (gnu_get_libc_version ()); return 0; }
Cheers !!!

Resources