Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msys2/mingw link failure #5

Closed
Alex-Gamper opened this issue Oct 12, 2019 · 5 comments
Closed

msys2/mingw link failure #5

Alex-Gamper opened this issue Oct 12, 2019 · 5 comments

Comments

@Alex-Gamper
Copy link

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
Copy link
Member

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
Copy link
Author

Alex-Gamper commented Oct 12, 2019

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
Copy link
Author

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  :=
  •    Add_Global_Function ("__gnat_personality_v0",
    
  •    Add_Global_Function ("__gnat_personality_seh0",
                            Fn_Ty ((1 .. 0 => <>), Int_Ty (Nat (32)), True),
                            Void_GL_Type);
    

@@ -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");

  •  Register_Global_Name ("__gnat_personality_v0");
    
  •  Register_Global_Name ("__gnat_personality_seh0");
     Register_Global_Name ("__gnat_reraise_zcx");
     Register_Global_Name ("__gnat_set_exception_parameter");
    

@ArnaudCharlet
Copy link
Member

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
Copy link
Author

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

Thanks Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants