Re: Functions and Global Variables defined in Libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2023-03-08 at 23:08 +0000, Frederick Virchanza Gotham via Gcc-help wrote:
> When I run it at the command line, the first thing I get is:
> 
>     ======================== pre_start - GUI========================
> 
> and then it continues execution as normal. No problems.
> 
> So then the next thing I did was I used 'patchelf' to remove the
> NEEDED for the graphical user interface library:
> 
>     patchelf --remove-needed libgtk-3.so.0 ./prog
> 
> And then I tried to run it again, but this time around I got back:
> 
>     ./ssh: symbol lookup error: ./ssh: undefined symbol: gtk_true
> 
> This means that the program falls over ***before*** the entry point is reached.

It does not happen to me:

$ cat t.c
#include <gtk/gtk.h>

int main()
{
	volatile int flag = 0;
	if (flag) {
		volatile int r = gtk_true ();
	}
}
$ cc t.c -I /usr/include/gtk-3.0 -I /usr/include/glib-2.0 -I /usr/lib/glib-2.0/include -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0
$ patchelf --remove-needed libgtk-3.so.0 ./a.out
$ objdump -d | grep 'call.*gtk' 
    117f:	e8 ac fe ff ff       	call   1030 <gtk_true@plt>
$ objdump -T | grep gtk
0000000000000000      DF *UND*	0000000000000000  Base        gtk_true
$ { readelf -d a.out | grep gtk; } || echo "nothing"
nothing
$ ./a.out && echo "fine"
fine

I guess it does not work for you because your distro has enabled
BIND_NOW (-Wl,-z,now) by default.

And anyway your question has nothing related to GCC.  Try to find a more
proper channel to discuss it.

-- 
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux