AdaCore / gnat-llvm

LLVM based GNAT compiler
179 stars 18 forks source link

msys2/mingw link failure #5

Closed Alex-Gamper closed 4 years ago

Alex-Gamper commented 4 years ago

Hi AdaCore

The Msys2 project have just released LLVM 9.0.0 and I have rebuilt gnat-LLVM with my local patches. So on to the next step to build a simple Ada program !

I get the below error with building a very simple "hello world" application which seems to indicate issues with the Ada runtime (ie libgnat/libgnarl) ???. Under msys2/mingw.

I seem to recall that the gnat_personality_v0 is the default exception handler under Linux, but Msyd2/Mingw uses gnat_personality_seh, which I believe is set by pre-processor directive SEH . I am not sure how exactly this should be set in the makefile ?

Any advice would be appreciated !

Thanks Alex

$ ./llvm-gnatmake.exe Hello.adb llvm-gcc -c hello.adb llvm-gnatbind -x hello.ali llvm-gnatlink hello.ali C:\msys64\mingw64\bin\ld: C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface/lib/rts-native/adalib\libgnat.a(a-except.o):a-except.adb:(.xdata+0x128): undefined reference to gnat_personality_v0' C:\msys64\mingw64\bin\ld: C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface\/lib/rts-native/adalib\libgnat.a(a-except.o):a-except.adb:(.xdata+0x240): undefined reference to gnat_personality_v0' C:\msys64\mingw64\bin\ld: C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface/lib/rts-native/adalib\libgnat.a(a-except.o):a-except.adb:(.xdata+0x420): undefined reference to gnat_personality_v0' C:\msys64\mingw64\bin\ld: C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface\/lib/rts-native/adalib\libgnat.a(a-except.o):a-except.adb:(.xdata+0x45c): undefined reference to gnat_personality_v0' C:\msys64\mingw64\bin\ld: C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface/lib/rts-native/adalib\libgnat.a(a-except.o):a-except.adb:(.xdata+0x498): undefined reference to gnat_personality_v0' C:\msys64\mingw64\bin\ld: C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface\/lib/rts-native/adalib\libgnat.a(a-finali.o):a-finali.adb:(.xdata+0x8): more undefined references to gnat_personality_v0' follow clang: error: linker command failed with exit code 1 (use -v to see invocation) llvm-gnatlink: error when calling C:\msys64\home\alexg\Software\gnat-llvm\llvm-interface\bin\llvm-gcc.exe llvm-gnatmake: *** link failed.

ArnaudCharlet commented 4 years ago

Can you try to apply the following patch:

--- llvm-interface/Makefile
+++ llvm-interface/Makefile
@@ -154,7 +154,7 @@ ADAFLAGS=-gnatpg
 ADA_INCLUDES=-nostdinc -I../adainclude
 CFLAGS=-O2 -g
 EXTRALIBFLAGS=
-GNATLIBCFLAGS=-DIN_RTS=1 -fexceptions -DSTANDALONE $(EXTRALIBFLAGS)
+GNATLIBCFLAGS=-DIN_RTS=1 -fexceptions -DSTANDALONE $(EXTRALIBFLAGS) -D__SEH__
 ALL_ADAFLAGS=$(CFLAGS) $(ADAFLAGS) $(ADA_INCLUDES) $(EXTRALIBFLAGS)
 INCLUDES=-I../adainclude -I../include

and do a "make gnatlib" and try again?

Alex-Gamper commented 4 years ago

That did not work, I did notice however that gnatllvm-blocks.adb makes explicit references to "__gnat_personality_v0". This does not look correct ?

Alex-Gamper commented 4 years ago

I made the following change in my repo and llvm-gnatmake now links/builds fine for a simple app. I'll do some more testing with some exception handling code, to see how the SEH exception handling works

Thanks Alex --- a/llvm-interface/gnatllvm-blocks.adb +++ b/llvm-interface/gnatllvm-blocks.adb @@ -635,7 +635,7 @@ package body GNATLLVM.Blocks is end if;

   Personality_Fn  :=

@@ -1747,7 +1747,7 @@ package body GNATLLVM.Blocks is Register_Global_Name ("gnat_begin_handler"); Register_Global_Name ("gnat_end_handler"); Register_Global_Name ("__gnat_others_value");

ArnaudCharlet commented 4 years ago

Ah yes indeed. We'll need to find a proper way to make this change work for all targets, but your patch will do the right thing on Windows.

Alex-Gamper commented 4 years ago

Now that I have a working build environment, I will try and do some more testing in my spare time

Thanks Alex