AdaCore / gtkada

Ada bindings for the GTK+ graphical library.
Other
88 stars 20 forks source link

Build failure on x86_64 linux: relocation R_X86_64_32 can not be used #10

Closed Earnestly closed 7 years ago

Earnestly commented 7 years ago

I cloned the repo, ran ./configure --prefix=/usr --with-GL=no (as suggested in https://github.com/AdaCore/gtkada/issues/9) and followed it with make PROCESSORS="$(nproc)"

This resulted in a relocation error:

...[snip]...

   [Ada]          gdk-display.adb
   [Ada]          gdk-device_manager.adb
   [Ada]          gdk-device.adb
   [Ada]          gdk-cursor.adb
   [C]            misc_generated.c
   [C]            misc.c
Build Libraries
   [gprlib]       gtkada.lexch
   [link library] libgtkada.so
/usr/bin/ld: /home/earnest/build/ada/ada-gtk-git/src/gtkada/src/obj/gtkada/relocatable/misc.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
gprlib: /usr/bin/gcc execution error
gprbuild: could not build library for project gtkada
make: *** [Makefile:85: build_library_type/relocatable] Error 4

Applying this patch appears to correct the issue:

diff --git a/shared.gpr.in b/shared.gpr.in
index ba14efeb..a4748844 100644
--- a/shared.gpr.in
+++ b/shared.gpr.in
@@ -60,12 +60,12 @@ project Shared is
              for Switches ("Ada") use
                 ("-gnat05", "-gnatQ", "-gnatwae", "-gnatay", "-g", "-O0",
                  "-Werror=format-security");
-             for Switches ("C") use ("-g", "-O0");
+             for Switches ("C") use ("-g", "-O0", "-fPIC");
          when "Production" =>
              for Switches ("Ada") use
                 ("-gnat05", "-gnatQ", "-O2", "-gnatn", "-gnatwa", "-gnaty",
                  "-Werror=format-security");
-             for Switches ("C") use ("-O2");
+             for Switches ("C") use ("-O2", "-fPIC");
       end case;

       for Switches ("C") use Compiler'Switches ("C") & Gtk_Include;
setton commented 7 years ago

Thank you! we'll have a look.

Earnestly commented 7 years ago

Is there anything blocking a fix?

setton commented 7 years ago

nothing, sorry for the delay! Just that we can't seem to reproduce out-of-the-box (tried on a relatively recent Ubuntu and a recently recent RedHat). What's your platform, just for the record?

Earnestly commented 7 years ago

Most of the details were listed in the bug report. Currently I'm using Arch Linux as a base which is essentially vanilla. If you want to see the build flags for gcc I can provide those.

One unique thing Arch does perhaps is that we remove most static libraries which aren't necessary which means gtkada is linking against shared objects which must be fPIC on x86 as I understand it.

setton commented 7 years ago

@Earnestly, could you please try the following patch instead, which uses the PIC_Option attribute? (Sorry, I couldn't make the time to install Arch Linux and do the test myself).

diff --git a/shared.gpr.in b/shared.gpr.in
index ba14efe..326ae11 100644
--- a/shared.gpr.in
+++ b/shared.gpr.in
@@ -54,6 +54,7 @@ project Shared is
       for Driver ("Objective-C") use "@OBJC@";
       for Leading_Required_Switches ("Objective-C") use ("-c");
       for PIC_Option ("Objective-C") use ("-fPIC");
+      for PIC_Option ("C") use ("-fPIC");

       case Build is
          when "Debug" =>
Earnestly commented 7 years ago

Great, I can confirm your patch does work.

Don't worry about installing Arch Linux; so long as you use relatively up to date software which has minimal tampering from upstream defaults, it should be fine. Shared libraries on x86_64 absolutely need PIC, gcc will even force it. http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2007-07/msg00513.html

Thank you!

Earnestly commented 7 years ago

Reopened on second consideration, I jumped the gun a bit since while the patch works, it's still only a patch

setton commented 7 years ago

and done :)

TamaMcGlinn commented 4 years ago

I have this problem, but neither of the patches work. I am on:

MarioBlunk commented 4 years ago

After a kernel update to 5.8.0 it seems the issue is back:

If I run: ./configure ./configure --with-GL=no

make

I get stuck with the error aforementioned.

/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: /home/xyz/git/BEL/ada_training/gtkada/gtkada-gtkada-17.0/src/obj/gtkada/relocatable/misc.o: relocation R_X86_64_32 against.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC collect2: error: ld returned 1 exit status gprlib: /usr/bin/gcc execution error gprbuild: could not build library for project gtkada make: *** [Makefile:84: build_library_type/relocatable] Error 4`

The system is:

How to proceed ? Thanks.

daniil-loban commented 2 years ago

Operating System: Kubuntu 20.04 KDE Plasma Version: 5.18.8 KDE Frameworks Version: 5.68.0 Qt Version: 5.12.8 Kernel Version: 5.4.0-131-generic OS Type: 64-bit gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

I have an error with gtkada-2021-x86_64-linux-bin : relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE

Enter the name of the directory in which you would like to install GtkAda

[/opt/gtkada]

Are you now ready to proceed with the installation [Y/n] ? Copying the Gtk+ binaries ... ====== Building tools ===== /usr/bin/gprbuild -j0 -m -p -XLIBRARY_TYPE=static -Psrc/tools/tools.gpr Bind [gprbind] gdialog.bexch [Ada] gdialog.ali Link [link] gdialog.adb /usr/bin/ld: /home/daniil/Downloads/gtkada-2021-x86_64-linux-bin/src/lib/gtkada/static/libgtkada.a(misc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE collect2: error: ld returned 1 exit status gprbuild: link of gdialog.adb failed gprbuild: failed command was: /usr/bin/gnatgcc gdialog.o b__gdialog.o /home/daniil/Downloads/gtkada-2021-x86_64-linux-bin/src/lib/gtkada/static/libgtkada.a -L/home/daniil/Downloads/gtkada-2021-x86_64-linux-bin//lib -L/home/daniil/Downloads/gtkada-2021-x86_64-linux-bin//bin -L/opt/gtkada/lib -L/it/sbx/wave/x86_64-linux/freetype-2.9.1-gtk-3.14/install/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lfontconfig -lfreetype -L/home/daniil/Downloads/gtkada-2021-x86_64-linux-bin/src/obj/tools/ -L/home/daniil/Downloads/gtkada-2021-x86_64-linux-bin/src/obj/tools/ -L/home/daniil/Downloads/gtkada-2021-x86_64-linux-bin/src/lib/gtkada/static/ -L/usr/lib/gcc/x86_64-linux-gnu/9/adalib/ -shared-libgcc -lgnat-9 -ldl -Wl,-rpath-link,/usr/lib/gcc/x86_64-linux-gnu/9//adalib -Wl,-z,origin,-rpath,$ORIGIN/../../..//lib:$ORIGIN/../../..//bin:/opt/gtkada/lib:/it/sbx/wave/x86_64-linux/freetype-2.9.1-gtk-3.14/install/lib:$ORIGIN/:$ORIGIN/../..//lib/gtkada/static:/usr/lib/gcc/x86_64-linux-gnu/9/adalib:/usr/lib64:/usr/lib -o gtkada-dialog make: *** [Makefile:81: tools] Error 4