• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How (not) to build .NET coreclr on FreeBSD

unitrunker

Member

Thanks: 23
Messages: 38

#1
Trying this out on FreeBSD 11.1

The proper build instructions for coreclr are here:

https://github.com/dotnet/coreclr/blob/master/Documentation/building/freebsd-instructions.md

Results from the documented instructions:

# git clone https://github.com/dotnet/coreclr.git
# cd coreclr
# ./build.sh clang50 release

I get errors the build script can't find llvm-ar, llvm-link, and llvm-nm. My dirty fix for this error is symbolic links in /usr/local/bin eg, 'ln -s llvm50-ar llvm-ar' etc. Preferably done inside a jail. That gets me farther along but no joy.

Code:
-- Configuring done
-- Generating done
-- Build files have been written to: ./coreclr/bin/obj/FreeBSD.x64.Release
~/coreclr
~/coreclr/bin/obj/FreeBSD.x64.Release ~/coreclr
Executing make install -j 5
[  0%] Building CXX object src/pal/src/eventprovider/CMakeFiles/eventprovider.dir/lttng/eventprovdotnetruntime.cpp.o
[  0%] Building CXX object src/corefx/System.Globalization.Native/CMakeFiles/System.Globalization.Native.dir/casing.cpp.o
[  0%] Building CXX object src/corefx/System.Globalization.Native/CMakeFiles/System.Globalization.Native_Static.dir/casing.cpp.o
In file included from ./coreclr/bin/obj/FreeBSD.x64.Release/eventing/eventprovider/lttng/eventprovdotnetruntime.cpp:24:
./coreclr/bin/obj/FreeBSD.x64.Release/eventing/eventprovider/lttng/tpdotnetruntime.h:29:10: fatal error: 'lttng/tracepoint.h' file not found
#include <lttng/tracepoint.h>
         ^~~~~~~~~~~~~~~~~~~~
[  0%] Building CXX object src/pal/src/CMakeFiles/coreclrpal.dir/cruntime/file.cpp.o
1 error generated.
The above looks like the typical goof of using angle brackets instead of quotes. I set this aside (may come back later) to try another approach.

The convention for most cmake builds is (a) mkdir build (b) cd build (c) cmake .. and (d) make. That almost works.
Missing a version.cpp and compiler looks for etmdummy.h in the wrong place. Two features "perftracing" and "even_trace" seem to be not implemented for this platform. Adding placebos allows cmake to progress. Also - these steps do not require the symbolic link hack above.

# git clone https://github.com/dotnet/coreclr.git
# cd coreclr
# mkdir build
# cd build
# touch version.cpp
# vi ../src/inc/etdummy.h
# (insert one line -> #include "../gc/env/etmdummy.h" )
# cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DFEATURE_PERFTRACING=0 -DFEATURE_EVENT_TRACE=0

This gets me further along than running "build.sh" above. cmake creates the Makefile(s). However, actual compile fails.

# make

Code:
[ 14%] Built target utilcode_dac
[ 14%] Building CXX object src/vm/dac/CMakeFiles/cee_dac.dir/__/gctoclreventsink.cpp.o
./coreclr/src/vm/gctoclreventsink.cpp:23:5: error: use of undeclared identifier 'FireEtwGCDynamicEvent'
    FireEtwGCDynamicEvent(wideEventName, payloadSize, (const BYTE*)payload, GetClrInstanceId());
    ^
1 error generated.
*** Error code 1
I do not see this symbol anywhere within coreclr. After commenting out that one line, the build progresses ...

Code:
[ 27%] Built target utilcode
[ 27%] Built target gcinfo
[ 27%] Building CXX object src/vm/wks/CMakeFiles/cee_wks.dir/__/prestub.cpp.o
./coreclr/src/vm/prestub.cpp:730:17: error: too many arguments to function call, expected at most 6, have 8
                pConfig->ProfilerRejectedPrecompiledCode(),
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./coreclr/src/inc/eventtracebase.h:614:9: note: 'MethodJitted' declared here
        static VOID MethodJitted(MethodDesc *pMethodDesc, SString *namespaceOrClassName=NULL, SString *methodName=NULL, SString *methodSignature=NULL, SIZE_T pCode = 0, ReJITID rejitID = 0) {};
        ^
1 error generated.
Still not there.
 

unitrunker

Member

Thanks: 23
Messages: 38

#2
Okay ... wiped everything. Started over with a clean git clone of coreclr. Switched to clang 4.0. Was missing pkg lttng-ust. Fixed that. The build.sh script passes the config phase (I see "configuing done"). Chokes on linking. lttng won't link.

libs are in the lib path (/usr/local/lib) ...

The cmake generated link.txt file is missing the "-L/usr/local/lib".

./src/pal/src/eventprovider/tracepointprovider/CMakeFiles/coreclrtraceptprovider.dir/link.txt:
/usr/bin/clang++ -fPIC -Wall -Wno-null-conversion -std=c++11 -g -O0 -Wl,--no-gc-sections -shared -Wl,-soname,libcoreclrtraceptprovider.so -o libcoreclrtraceptprovider.so CMakeFiles/coreclrtraceptprovider.dir/__/lttng/traceptprovdotnetruntime.cpp.o CMakeFiles/coreclrtraceptprovider.dir/__/lttng/traceptprovdotnetruntimerundown.cpp.o CMakeFiles/coreclrtraceptprovider.dir/__/lttng/traceptprovdotnetruntimestress.cpp.o CMakeFiles/coreclrtraceptprovider.dir/__/lttng/traceptprovdotnetruntimeprivate.cpp.o -llttng-ust
 

unitrunker

Member

Thanks: 23
Messages: 38

#3
[100%] built target ilasm


Wow. That works. Need to figure out how to tell cmake to do the right thing (eg. pass the "-L/usr/local/lib") so I don't have to hand-edit a generated link.txt file.
 

unitrunker

Member

Thanks: 23
Messages: 38

#4
Woo hoo! Seems to work ...


./ilasm
Usage: ilasm [Options] <sourcefile> [Options]

Options:
/NOLOGO Don't type the logo
/QUIET Don't report assembly progress
/NOAUTOINHERIT Disable inheriting from System.Object by default
/DLL Compile to .dll
/EXE Compile to .exe (default)
/PDB Create the PDB file without enabling debug info tracking
/APPCONTAINER Create an AppContainer exe or dll
/DEBUG Disable JIT optimization, create PDB file, use sequence points from PDB
/DEBUG=IMPL Disable JIT optimization, create PDB file, use implicit sequence points
/DEBUG=OPT Enable JIT optimization, create PDB file, use implicit sequence points
/OPTIMIZE Optimize long instructions to short
/FOLD Fold the identical method bodies into one
/CLOCK Measure and report compilation times
/RESOURCE=<res_file> Link the specified resource file (*.res)
into resulting .exe or .dll
/OUTPUT=<targetfile> Compile to file with specified name
(user must provide extension, if any)
/KEY=<keyfile> Compile with strong signature
(<keyfile> contains private key)
/KEY=@<keysource> Compile with strong signature
(<keysource> is the private key source name)
/INCLUDE=<path> Set path to search for #include'd files
/SUBSYSTEM=<int> Set Subsystem value in the NT Optional header
/SSVER=<int>.<int> Set Subsystem version number in the NT Optional header
/FLAGS=<int> Set CLR ImageFlags value in the CLR header
/ALIGNMENT=<int> Set FileAlignment value in the NT Optional header
/BASE=<int> Set ImageBase value in the NT Optional header (max 2GB for 32-bit images)
/STACK=<int> Set SizeOfStackReserve value in the NT Optional header
/MDV=<version_string> Set Metadata version string
/MSV=<int>.<int> Set Metadata stream version (<major>.<minor>)
/PE64 Create a 64bit image (PE32+)
/HIGHENTROPYVA Set High Entropy Virtual Address capable PE32+ images (default for /APPCONTAINER)
/NOCORSTUB Suppress generation of CORExeMain stub
/STRIPRELOC Indicate that no base relocations are needed
/ITANIUM Target processor: Intel Itanium
/X64 Target processor: 64bit AMD processor
/ARM Target processor: ARM processor
/32BITPREFERRED Create a 32BitPreferred image (PE32)
/ENC=<file> Create Edit-and-Continue deltas from specified source file

Key may be '-' or '/'
Options are recognized by first 3 characters
Default source file extension is .il

Target defaults:
/PE64 => /PE64 /ITANIUM
/ITANIUM => /PE64 /ITANIUM
/X64 => /PE64 /X64
 

unitrunker

Member

Thanks: 23
Messages: 38

#5
This works ... CMakeLists.txt ...

Before:
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
set(CLR_CMAKE_PLATFORM_FREEBSD 1)
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)

After:
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
set(CLR_CMAKE_PLATFORM_FREEBSD 1)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)


This avoids hand-editing the link.txt file. Need to figure out how to use the chosen clang version (eg 4.0 vs. 5.0) instead of assuming the default.
 

HL1234

Active Member

Thanks: 7
Messages: 114

#6
There is an other link to handle with building CoreCLR on FreeBSD:

https://github.com/dotnet/corefx/wiki/Building-.NET-Core--2.x-on-FreeBSD

How I do understand, one of the sence of building CoreCLR, is the following:
Running ASP.NET Core2 Websites with the build in web-server Kestrel in an ASP.NET core2 web project
( Kestrel web server implementation in ASP.NET Core see https://docs.microsoft.com/de-de/as...kestrel?view=aspnetcore-2.1&tabs=aspnetcore2x) and using apache2x or nginx as reverse proxy:

1523803944226.png

Until now there is a completed instruction for Linux, MAC and sure Windows - but I missed some what real works with FreeBSD. Later on it would be fine to have a port for installing CoreCLR.
ASP.NET core or .Net-Framework core are the "core" open source components of the proprietary .NET Framework of Microsoft for different famous OS platforms - but FreeBSD until now is missing for it
(Maybe this forum thread belongs better to Programming)
 

unitrunker

Member

Thanks: 23
Messages: 38

#7
I've set aside Microsoft's coreclr in favor of monodevelop. It is much better supported from pkg and ports. It would be cool to have an "official" CLR but this isn't a blocker.