FLTK logo

Re: [fltk.general] -no-pie in FLTK Libraries build.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: -no-pie in FLTK Libraries build. "'Albrecht Schlosser' via fltk.general" 06:43 Mar 17  
  On 3/17/24 06:52 Rob McDonald wrote:
In addition to building an executable binary of my application, I also use SWIG to wrap my program to be called from Python.

SWIG sets up a shared object library that gets loaded by Python. ...

Noted, but I can't comment on anything related to SWIG or Python.

When we create this shared object, we try to statically link everything we can -- including FLTK.  So, we're statically linking FLTK into a shared library.
For some reason, on RHEL9, when I go to link the Python wrapper with FLTK into the shared object, I get the following error:

/usr/bin/ld: crt1.0: in function `_start': (.text+0x1b): undefined reference to `main’
collect2: error: ld returned 1 exit status

Of course, since this is a shared object, I don't have a main().

I dug into the details of the linker command and eventually discovered that it included a '-no-pie' that if removed, linking would proceed as desired.

OK, I believe this is a bug in our CMake files... see below.

After considerable digging, I figured out that the '-no-pie' is coming from fltk:fltk.  I used this utility (discussed previously here) to peer into everything in this target.  The output is below:

[...]
fltk::fltk INTERFACE_LINK_LIBRARIES = /usr/lib64/libdl.a;/usr/lib64/libX11.so;/usr/lib64/libXext.so;/usr/lib64/libXinerama.so;/usr/lib64/libXfixes.so;/usr/lib64/libXcursor.so;/usr/lib64/libXrender.so;/usr/lib64/libpango-1.0.so;/usr/lib64/libpangocairo-1.0.so;/usr/lib64/libcairo.so;/usr/lib64/libgobject-2.0.so;/usr/lib64/libpangoxft-1.0.so;/usr/lib64/libXft.so;/usr/lib64/libfontconfig.so;-lwayland-egl -lEGL;-L/usr/lib64;-lgtk-3;-lgdk-3;-lpangocairo-1.0;-lpango-1.0;-lharfbuzz;-latk-1.0;-lcairo-gobject;-lcairo;-lgdk_pixbuf-2.0;-lgio-2.0;-lgobject-2.0;-lglib-2.0;-lwayland-cursor -lwayland-client -lxkbcommon -ldl;-L/usr/lib64;-ldbus-1;-no-pie
[...]


Notice that INTERFACE_LINK_LIBRARIES contains -no-pie.  Notably, this is a linker option, not a library.

You're IMHO correct, this shouldn't be there.

The FLTKConfig.cmake.in file contains no reference to -no-pie.  So I dug into the FLTK source, and there are three hits.  One in ./configure.ac, one in libdecor, and the relevant one in /src/CMakeLists.txt:768.

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND NOT FLTK_BUILD_SHARED_LIBS)
list(APPEND OPTIONAL_LIBS "-no-pie")
endif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND NOT FLTK_BUILD_SHARED_LIBS)

This is perhaps a reasonable thing to do if you assume that fltk is going to be statically linked into an executable program.  It does not work in my situation where fltk is statically linked into a shared library.

I am also not certain how appropriate it is that this 'leaks' its way into the fltk:fltk target.

That's probably due to some "old code" leaking into the "Modern CMake" approach. I didn't have the time yet to rewrite everything and I'm aware that there's still something to do.

Perhaps it must be this way.  I don't fully understand all the mechanisms at work.

I don't think that it must be this way, I'll check this...

At a minimum, I'm pretty sure this should be assigned to a target LINK_OPTIONS property.  Or, perhaps even better, a target POSITION_INDEPENDENT_CODE property (rather than appended to a string list of library names).

Yep, that's correct, and very likely it should be added to PRIVATE CMake properties rather than PUBLIC, hence it would not affect your build at all (PRIVATE properties are not included in INTERFACE_* properties).

I don't know the long-term fix for this.

I'll check if I can fix this.

In the short term, I'm going to attempt something like

get_target_property(templist fltk:fltk INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM templist "-no-pie")
set_target_properties(fltk:fltk PROPERTIES INTERFACE_LINK_LIBRARIES ${templist})

Or something like that.

Might work but it's only a workaround.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/d118804e-f83c-45de-880c-2c1fa1c996b9%40aljus.de.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.