Bug 58230 - LLVM JIT fails under some combination of PIE, -fno-plt, -Wl,-z,now
Summary: LLVM JIT fails under some combination of PIE, -fno-plt, -Wl,-z,now
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-19 05:05 UTC by Mark Laws
Modified: 2017-07-30 18:49 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
apply on top of 975e3a6903003d7dba1b01f8a3c4a42a55049842 (2.53 KB, patch)
2017-07-20 10:57 UTC, Mark Laws
Details
apply on top of 574f999d5558e5e59ab0d09c7488563590836241 (1.43 KB, patch)
2017-07-20 11:07 UTC, Mark Laws
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Mark Laws 2017-07-19 05:05:18 UTC
The LLVM JIT used to work, but no longer does as of this change (using Arch as an example, since that's what I'm running):

https://git.archlinux.org/svntogit/community.git/commit/trunk?h=packages/gcc-multilib&id=0ee30871faa10dd32e74e80bebb0555e76790dde

I am using the Mono LLVM fork from here:

https://github.com/mono/llvm

The version that previously was working for me was the master branch (LLVM 3.6 SVN).  Just to make sure, I also tried against the "llvm-master" (based on LLVM 3.9 SVN) and "2017-07-06-5a1ffa96376e8a3ee895b782790591e5e7814ccf" (LLVM 5.0 SVN) branches (both which I had to heavily patch in order to build, but they also crash).

An example backtrace:
=====================

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) object.__icall_wrapper_mono_generic_class_init (intptr) [0x00000] in <4ffeca6e4a524d7e9ff6dcd375e35a41>:0
  at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser..ctor (bool) <0x00025>
  at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser..cctor () <0x00027>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0x00065>
  at <unknown> <0xffffffff>
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc..ctor (string,Microsoft.CodeAnalysis.BuildPaths,string[],Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader) <0x0001d>
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run (string[],Microsoft.CodeAnalysis.BuildPaths,System.IO.TextWriter,Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader) <0x000f9>
  at (wrapper delegate-invoke) <Module>.invoke_int_string[]_BuildPaths_TextWriter_IAnalyzerAssemblyLoader (string[],Microsoft.CodeAnalysis.BuildPaths,System.IO.TextWriter,Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader) <0x000fe>
  at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.RunLocalCompilation (string[],Microsoft.CodeAnalysis.BuildPaths,System.IO.TextWriter) <0x00024>
  at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation (System.Collections.Generic.IEnumerable`1<string>,Microsoft.CodeAnalysis.BuildPaths,System.IO.TextWriter) <0x001ff>
  at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run (System.Collections.Generic.IEnumerable`1<string>,Microsoft.CodeAnalysis.CommandLine.RequestLanguage,Microsoft.CodeAnalysis.CommandLine.CompileFunc,Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader) <0x000dc>
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore (string[]) <0x00084>
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main (string[]) <0x00005>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0x000ad>
/proc/self/maps:
40aef000-40b0f000 rwxp 00000000 00:00 0
41258000-41268000 rwxp 00000000 00:00 0
555f48436000-555f49544000 r-xp 00000000 08:02 419589                     /usr/bin/mono-sgen
555f49744000-555f497d9000 r--p 0110e000 08:02 419589                     /usr/bin/mono-sgen
555f497d9000-555f497dd000 rw-p 011a3000 08:02 419589                     /usr/bin/mono-sgen
555f497dd000-555f4983e000 rw-p 00000000 00:00 0
555f4ae48000-555f4b230000 rw-p 00000000 00:00 0                          [heap]
7f7a78000000-7f7a78021000 rw-p 00000000 00:00 0
7f7a78021000-7f7a7c000000 ---p 00000000 00:00 0
7f7a7dc31000-7f7a7dc6d000 r--p 00000000 08:02 732110                     /var/cache/pacaur/aurdest/mono-git/src/mono/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.0/tools/System.Collections.Immutable.dll
7f7a7dc6d000-7f7a7df0b000 r--p 00000000 08:02 749706                     /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
7f7a7df0b000-7f7a7e0fa000 r--p 00000000 08:02 732109                     /var/cache/pacaur/aurdest/mono-git/src/mono/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.0/tools/Microsoft.CodeAnalysis.dll
7f7a7e0fa000-7f7a7e53c000 r--p 00000000 08:02 732107                     /var/cache/pacaur/aurdest/mono-git/src/mono/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.0/tools/Microsoft.CodeAnalysis.CSharp.dll
7f7a7e53c000-7f7a7e545000 ---p 00000000 00:00 0
7f7a7e545000-7f7a7e73d000 rw-p 00000000 00:00 0
7f7a7e73d000-7f7a7ee2b000 r-xp 00000000 08:02 419488                     /usr/lib/mono/4.5/mscorlib.dll.so
7f7a7ee2b000-7f7a7f02a000 ---p 006ee000 08:02 419488                     /usr/lib/mono/4.5/mscorlib.dll.so
7f7a7f02a000-7f7a7f02b000 r--p 006ed000 08:02 419488                     /usr/lib/mono/4.5/mscorlib.dll.so
7f7a7f02b000-7f7a7f02c000 rw-p 006ee000 08:02 419488                     /usr/lib/mono/4.5/mscorlib.dll.so
7f7a7f02c000-7f7a7f049000 rw-p 00000000 00:00 0
7f7a7f049000-7f7a7f3ff000 r--p 00000000 08:02 419276                     /usr/lib/mono/4.5/mscorlib.dll
7f7a7f3ff000-7f7a803ff000 rw-p 00000000 00:00 0
7f7a803ff000-7f7a80400000 ---p 00000000 00:00 0
7f7a80400000-7f7a81000000 rw-p 00000000 00:00 0
7f7a81015000-7f7a81017000 r--p 00000000 08:02 750617                     /usr/lib/mono/4.5/Facades/System.Threading.dll
7f7a81017000-7f7a81018000 rw-p 00000000 00:00 0
7f7a81018000-7f7a8101a000 r--p 00000000 08:02 750675                     /usr/lib/mono/4.5/Facades/System.IO.FileSystem.dll
7f7a8101a000-7f7a8101c000 r--p 00000000 08:02 750652                     /usr/lib/mono/4.5/Facades/System.Text.Encoding.dll
7f7a8101c000-7f7a8101e000 r--p 00000000 08:02 750639                     /usr/lib/mono/4.5/Facades/System.Globalization.dll
7f7a8101e000-7f7a81020000 r--p 00000000 08:02 750725                     /usr/lib/mono/4.5/Facades/System.Resources.ResourceManager.dll
7f7a81020000-7f7a81022000 r--p 00000000 08:02 750690                     /usr/lib/mono/4.5/Facades/System.Runtime.Extensions.dll
7f7a81022000-7f7a8111a000 r--p 00000000 08:02 749624                     /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
7f7a8111a000-7f7a8119a000 rwxp 00000000 00:00 0
7f7a8119a000-7f7a8124d000 rw-p 00000000 00:00 0
7f7a8124d000-7f7a8124f000 r--p 00000000 08:02 750657                     /usr/lib/mono/4.5/Facades/System.Reflection.dll
7f7a8124f000-7f7a81250000 rw-p 00000000 00:00 0
7f7a81250000-7f7a812af000 ---p 00000000 00:00 0
7f7a812af000-7f7a8144c000 r-xp 00000000 08:02 395923                     /usr/lib/libc-2.25.so
7f7a8144c000-7f7a8164b000 ---p 0019d000 08:02 395923                     /usr/lib/libc-2.25.so
7f7a8164b000-7f7a8164f000 r--p 0019c000 08:02 395923                     /usr/lib/libc-2.25.so
7f7a8164f000-7f7a81651000 rw-p 001a0000 08:02 395923                     /usr/lib/libc-2.25.so
7f7a81651000-7f7a81655000 rw-p 00000000 00:00 0
7f7a81655000-7f7a8166b000 r-xp 00000000 08:02 420889                     /usr/lib/libgcc_s.so.1
7f7a8166b000-7f7a8186a000 ---p 00016000 08:02 420889                     /usr/lib/libgcc_s.so.1
7f7a8186a000-7f7a8186b000 r--p 00015000 08:02 420889                     /usr/lib/libgcc_s.so.1
7f7a8186b000-7f7a8186c000 rw-p 00016000 08:02 420889                     /usr/lib/libgcc_s.so.1
7f7a8186c000-7f7a81885000 r-xp 00000000 08:02 395895                     /usr/lib/libpthread-2.25.so
7f7a81885000-7f7a81a84000 ---p 00019000 08:02 395895                     /usr/lib/libpthread-2.25.so
7f7a81a84000-7f7a81a85000 r--p 00018000 08:02 395895                     /usr/lib/libpthread-2.25.so
7f7a81a85000-7f7a81a86000 rw-p 00019000 08:02 395895                     /usr/lib/libpthread-2.25.so
7f7a81a86000-7f7a81a8a000 rw-p 00000000 00:00 0
7f7a81a8a000-7f7a81a8d000 r-xp 00000000 08:02 395957                     /usr/lib/libdl-2.25.so
7f7a81a8d000-7f7a81c8c000 ---p 00003000 08:02 395957                     /usr/lib/libdl-2.25.so
7f7a81c8c000-7f7a81c8d000 r--p 00002000 08:02 395957                     /usr/lib/libdl-2.25.so
7f7a81c8d000-7f7a81c8e000 rw-p 00003000 08:02 395957                     /usr/lib/libdl-2.25.so
7f7a81c8e000-7f7a81c95000 r-xp 00000000 08:02 395893                     /usr/lib/librt-2.25.so
7f7a81c95000-7f7a81e94000 ---p 00007000 08:02 395893                     /usr/lib/librt-2.25.so
7f7a81e94000-7f7a81e95000 r--p 00006000 08:02 395893                     /usr/lib/librt-2.25.so
7f7a81e95000-7f7a81e96000 rw-p 00007000 08:02 395893                     /usr/lib/librt-2.25.so
7f7a81e96000-7f7a81fa7000 r-xp 00000000 08:02 395964                     /usr/lib/libm-2.25.so
7f7a81fa7000-7f7a821a6000 ---p 00111000 08:02 395964                     /usr/lib/libm-2.25.so
7f7a821a6000-7f7a821a7000 r--p 00110000 08:02 395964                     /usr/lib/libm-2.25.so
7f7a821a7000-7f7a821a8000 rw-p 00111000 08:02 395964                     /usr/lib/libm-2.25.so
7f7a821a8000-7f7a82322000 r-xp 00000000 08:02 399810                     /usr/lib/libstdc++.so.6.0.24
7f7a82322000-7f7a82521000 ---p 0017a000 08:02 399810                     /usr/lib/libstdc++.so.6.0.24
7f7a82521000-7f7a8252b000 r--p 00179000 08:02 399810                     /usr/lib/libstdc++.so.6.0.24
7f7a8252b000-7f7a8252d000 rw-p 00183000 08:02 399810                     /usr/lib/libstdc++.so.6.0.24
7f7a8252d000-7f7a82530000 rw-p 00000000 00:00 0
7f7a82530000-7f7a82598000 r-xp 00000000 08:02 423113                     /usr/lib/libncursesw.so.6.0
7f7a82598000-7f7a82797000 ---p 00068000 08:02 423113                     /usr/lib/libncursesw.so.6.0
7f7a82797000-7f7a8279b000 r--p 00067000 08:02 423113                     /usr/lib/libncursesw.so.6.0
7f7a8279b000-7f7a8279d000 rw-p 0006b000 08:02 423113                     /usr/lib/libncursesw.so.6.0
7f7a8279d000-7f7a827b3000 r-xp 00000000 08:02 399581                     /usr/lib/libz.so.1.2.11
7f7a827b3000-7f7a829b2000 ---p 00016000 08:02 399581                     /usr/lib/libz.so.1.2.11
7f7a829b2000-7f7a829b3000 r--p 00015000 08:02 399581                     /usr/lib/libz.so.1.2.11
7f7a829b3000-7f7a829b4000 rw-p 00016000 08:02 399581                     /usr/lib/libz.so.1.2.11
7f7a829b4000-7f7a829d7000 r-xp 00000000 08:02 395913                     /usr/lib/ld-2.25.so
7f7a829d8000-7f7a829da000 r--p 00000000 08:02 750638                     /usr/lib/mono/4.5/Facades/System.Threading.Tasks.dll
7f7a829da000-7f7a829dc000 r--p 00000000 08:02 750620                     /usr/lib/mono/4.5/Facades/System.IO.dll
7f7a829dc000-7f7a829de000 r--p 00000000 08:02 750664                     /usr/lib/mono/4.5/Facades/System.IO.FileSystem.Primitives.dll
7f7a829de000-7f7a829e2000 r--p 00000000 08:02 750706                     /usr/lib/mono/4.5/Facades/System.Runtime.dll
7f7a829e2000-7f7a829ef000 r--p 00000000 08:02 732112                     /var/cache/pacaur/aurdest/mono-git/src/mono/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.0/tools/csc.exe
7f7a829ef000-7f7a82a21000 rw-p 00000000 00:00 0
7f7a82a21000-7f7a82bb9000 r--p 00000000 08:02 423124                     /usr/lib/locale/locale-archive
7f7a82bb9000-7f7a82bc1000 rw-p 00000000 00:00 0
7f7a82bc1000-7f7a82bc3000 r--p 00000000 08:02 750659                     /usr/lib/mono/4.5/Facades/System.Collections.dll
7f7a82bc3000-7f7a82bd6000 rw-p 00000000 00:00 0
7f7a82bd6000-7f7a82bd7000 rw-s 00000000 00:15 1123054                    /dev/shm/mono.36078
7f7a82bd7000-7f7a82bd8000 r--p 00023000 08:02 395913                     /usr/lib/ld-2.25.so
7f7a82bd8000-7f7a82bd9000 rw-p 00024000 08:02 395913                     /usr/lib/ld-2.25.so
7f7a82bd9000-7f7a82bda000 rw-p 00000000 00:00 0
7ffd35d15000-7ffd35d1d000 ---p 00000000 00:00 0
7ffd364f2000-7ffd36514000 rw-p 00000000 00:00 0                          [stack]
7ffd36570000-7ffd36572000 r--p 00000000 00:00 0                          [vvar]
7ffd36572000-7ffd36574000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

Native stacktrace:


Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser..ctor (System.Boolean isScriptRunner) <0x40afee00 + 0x00025> in <73d448c1572d47cfa571852952475727>:0
  at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser..cctor () <0x40afe9f0 + 0x00027> in <73d448c1572d47cfa571852952475727>:0
   --- End of inner exception stack trace ---
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc..ctor (System.String responseFile, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.String[] args, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerLoader) <0x40afe8e0 + 0x0001d> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run (System.String[] args, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.IO.TextWriter textWriter, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerLoader) <0x40afe0f0 + 0x000f9> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at (wrapper delegate-invoke) <Module>:invoke_int_string[]_BuildPaths_TextWriter_IAnalyzerAssemblyLoader (string[],Microsoft.CodeAnalysis.BuildPaths,System.IO.TextWriter,Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader)
  at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.RunLocalCompilation (System.String[] arguments, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.IO.TextWriter textWriter) <0x40afde20 + 0x00024> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation (System.Collections.Generic.IEnumerable`1[T] originalArguments, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.IO.TextWriter textWriter) <0x40af92b0 + 0x001ff> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run (System.Collections.Generic.IEnumerable`1[T] arguments, Microsoft.CodeAnalysis.CommandLine.RequestLanguage language, Microsoft.CodeAnalysis.CommandLine.CompileFunc compileFunc, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerAssemblyLoader) <0x40af2ad0 + 0x000dc> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore (System.String[] args) <0x40af07e0 + 0x00084> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main (System.String[] args) <0x40af0330 + 0x00005> in <71471eaa6d6b4ba1bbce4fce42485556>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser..ctor (System.Boolean isScriptRunner) <0x40afee00 + 0x00025> in <73d448c1572d47cfa571852952475727>:0
  at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser..cctor () <0x40afe9f0 + 0x00027> in <73d448c1572d47cfa571852952475727>:0
   --- End of inner exception stack trace ---
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc..ctor (System.String responseFile, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.String[] args, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerLoader) <0x40afe8e0 + 0x0001d> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run (System.String[] args, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.IO.TextWriter textWriter, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerLoader) <0x40afe0f0 + 0x000f9> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at (wrapper delegate-invoke) <Module>:invoke_int_string[]_BuildPaths_TextWriter_IAnalyzerAssemblyLoader (string[],Microsoft.CodeAnalysis.BuildPaths,System.IO.TextWriter,Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader)
  at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.RunLocalCompilation (System.String[] arguments, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.IO.TextWriter textWriter) <0x40afde20 + 0x00024> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation (System.Collections.Generic.IEnumerable`1[T] originalArguments, Microsoft.CodeAnalysis.BuildPaths buildPaths, System.IO.TextWriter textWriter) <0x40af92b0 + 0x001ff> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run (System.Collections.Generic.IEnumerable`1[T] arguments, Microsoft.CodeAnalysis.CommandLine.RequestLanguage language, Microsoft.CodeAnalysis.CommandLine.CompileFunc compileFunc, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerAssemblyLoader) <0x40af2ad0 + 0x000dc> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore (System.String[] args) <0x40af07e0 + 0x00084> in <71471eaa6d6b4ba1bbce4fce42485556>:0
  at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main (System.String[] args) <0x40af0330 + 0x00005> in <71471eaa6d6b4ba1bbce4fce42485556>:0
Comment 2 Mark Laws 2017-07-20 10:57:49 UTC
Created attachment 23687 [details]
apply on top of 975e3a6903003d7dba1b01f8a3c4a42a55049842

mono-llvm
=========
git clone https://github.com/mono/llvm.git && cd llvm && git checkout 975e3a6 # master^

mkdir build && cd build

# set up original flags
export \
  CPPFLAGS="-D_FORTIFY_SOURCE=2" \
  CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" \
  CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" \
  LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"

# fix up flags
CFLAGS="$(echo $CFLAGS | sed -e 's/-fno-plt//g') -fplt -fno-PIE -no-pie"
CXXFLAGS="$(echo $CXXFLAGS | sed -e 's/-fno-plt//g') -fplt -fno-PIE -no-pie"
LDFLAGS="$(echo $LDFLAGS | sed -e 's/-z,now/-z,lazy/g')"

# configure
cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr/lib/mono-llvm \
  -DBUILD_SHARED_LIBS=ON \
  -DLLVM_TARGETS_TO_BUILD="X86;CppBackend" \
  -DLLVM_ENABLE_EH=ON \
  -DLLVM_ENABLE_RTTI=ON \
  -DLLVM_INSTALL_UTILS=ON \
  -DLLVM_ENABLE_FFI=ON \
  -DLLVM_BUILD_TESTS=OFF \
  -DLLVM_BUILD_DOCS=OFF \
  -DLLVM_ENABLE_SPHINX=OFF \
  -DLLVM_ENABLE_DOXYGEN=OFF \
  -DLLDB_DISABLE_LIBEDIT=1 \
  -DSPHINX_WARNINGS_AS_ERRORS=OFF \
  -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
  -DLLVM_BINUTILS_INCDIR=/usr/include \
  ..
make -j$(getconf _NPROCESSORS_CONF)
cd ..
make -C build -j1 install
Comment 3 Mark Laws 2017-07-20 11:07:39 UTC
Created attachment 23688 [details]
apply on top of 574f999d5558e5e59ab0d09c7488563590836241

mono
====
git clone https://github.com/mono/mono.git && cd mono && git checkout 574f999 # master

# set up original flags
export \
  CPPFLAGS="-D_FORTIFY_SOURCE=2" \
  CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" \
  CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" \
  LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"

# fix up flags
CFLAGS="$(echo $CFLAGS | sed -e 's/-fno-plt//g') -fplt -fno-PIE -no-pie" \
CXXFLAGS="$(echo $CXXFLAGS | sed -e 's/-fno-plt//g') -fplt -fno-PIE -no-pie" \
LDFLAGS="$(echo $LDFLAGS | sed -e 's/-z,now/-z,lazy/g'),-rpath,/usr/lib/mono-llvm/lib"

# configure
./autogen.sh         \
  --prefix=/usr      \
  --sbindir=/usr/bin \
  --sysconfdir=/etc  \
  --with-mcs-docs=no \
  --with-llvm=/usr/lib/mono-llvm \
  --enable-llvm
make -j$(getconf _NPROCESSORS_CONF)
make install
cd mcs/jay && make prefix=/usr INSTALL=../../install-sh install
Comment 4 Mark Laws 2017-07-20 11:16:41 UTC
I was able to get the LLVM backend working again with the changes and build procedures above.  The problem is caused by one or more of the following:

* -fno-plt
* -fPIE -pie
* -Wl,-z,now

With these, the LLVM backend works:

* -fplt
* -fno-PIE -no-pie
* -Wl,-z,lazy

I don't know enough about the guts of the Mono or the Mono LLVM changes to be able to offer a fix, but this should be enough to allow you to reproduce the problem and to compare the behavior of both configurations.
Comment 6 Zoltan Varga 2017-07-20 14:36:59 UTC
They contain our changes on top of a given llvm revision, i.e. the second one is branched from llvm 5a1ffa96376e8a3ee895b782790591e5e7814ccf. They are not for external use.
Comment 7 Mark Laws 2017-07-20 14:44:14 UTC
Ah, I see.  Thanks for the clarification.

Let me know if you need anything more to reproduce this bug--I can give you my PKGBUILDs if you want them.
Comment 8 Zoltan Varga 2017-07-20 14:49:36 UTC
Is there a docker vm somewhere which has this configuration ?
Comment 9 Mark Laws 2017-07-20 15:01:14 UTC
I don't use docker, but this image gets automatically updated and has compilers etc. pre-installed:

https://hub.docker.com/r/base/devel/

You should be able to build Mono from that.
Comment 10 Zoltan Varga 2017-07-20 22:50:26 UTC
So using the default build of llvm/mono would crash, and the patches above are a fix/workaround ?
Comment 11 Mark Laws 2017-07-20 22:59:09 UTC
The default build used to work, but because of the previously-linked changes, the default build no longer works.  This isn't specific to anything unique about Arch--the problem would occur on any distribution with a similar setup.  The above patches are a workaround (fix?) to effectively do the same build as the one that used to take place.
Comment 12 Zoltan Varga 2017-07-21 02:22:22 UTC
As a workaround, revert 2aaa79a14d18e505a0f45c163ac92135e0920c6e from the mono llvm tree.

It was added to generate better code by forcing all calls to be direct, but that breaks if the caller and callee are too far from each other on 64 bit platforms. We force llvm generated code to have a 32 bit address, but can't force the runtime code to have one so when these security features are enabled, things will break.
Comment 13 Mark Laws 2017-07-21 02:30:50 UTC
Ah ha.  That makes sense.  Would there be any reason to go with that workaround over the one I supplied here?
Comment 14 Zoltan Varga 2017-07-21 02:40:46 UTC
That will probably be the real fix, the assumptions that commit depended on do not seem to hold anymore.
Comment 15 Zoltan Varga 2017-07-30 18:49:18 UTC
Should be fixed by llvm 21492ec92e255a43bc6b687468f1eb18a635d94e.