Skip to content

Commit

Permalink
Add scripts for building ObjWriter (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLapounov authored Jan 20, 2021
2 parents 7bb4094 + 115f3d8 commit 04aba0b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
5 changes: 5 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<SubsetName Include="NativeAot" Description="The CoreCLR native AOT runtime, libraries, and tools." />
<SubsetName Include="NativeAot.Libs" Description="The CoreCLR native AOT CoreLib and other low level class libraries." />
<SubsetName Include="NativeAot.Tools" Description="The CoreCLR native AOT compiler." />
<SubsetName Include="NativeAot.ObjWriter" Description="Object writer for the CoreCLR native AOT compiler." />
<SubsetName Include="NativeAot.Packages" Description="The CoreCLR native AOT compiler." />

<!-- CoreClr -->
Expand Down Expand Up @@ -238,6 +239,10 @@
<ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\BuildIntegration\BuildIntegration.proj" Category="clr" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+nativeaot.objwriter+'))">
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ObjWriter\objwriter.proj" Category="clr" />
</ItemGroup>

<!-- Mono sets -->
<ItemGroup Condition="$(_subset.Contains('+mono.llvm+')) or $(_subset.Contains('+mono.aotcross+')) or '$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'Android' or '$(TargetOS)' == 'Browser'">
<ProjectToBuild Include="$(MonoProjectRoot)llvm\llvm-init.proj" Category="mono" />
Expand Down
23 changes: 23 additions & 0 deletions src/coreclr/Tools/aot/ObjWriter/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@echo off
setlocal

:: Clone the LLVM repo
pushd %1 || exit /b 1
if not exist llvm (
git clone -b release_50 https://github.com/llvm-mirror/llvm.git || exit /b 1
)

:: Clean the tree and apply the patch
cd llvm && git restore . || exit /b 1
git apply "%~dp0llvm.patch" || exit /b 1

:: Copy ObjWriter files
robocopy /mir "%~dp0\" tools\ObjWriter
if %ErrorLevel% geq 8 exit /b %ErrorLevel%

:: Configure and build
if not exist build mkdir build
cd build || exit /b 1

cmake ../ -DCMAKE_BUILD_TYPE=Release -DLLVM_OPTIMIZED_TABLEGEN=1 -DHAVE_POSIX_SPAWN=0 -DLLVM_ENABLE_PIC=1 -DLLVM_BUILD_TESTS=0 -DLLVM_ENABLE_DOXYGEN=0 -DLLVM_INCLUDE_DOCS=0 -DLLVM_INCLUDE_TESTS=0 -DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64" -DCMAKE_INSTALL_PREFIX=install || exit /b 1
cmake --build . -j 10 --config Release --target install || exit /b 1
23 changes: 23 additions & 0 deletions src/coreclr/Tools/aot/ObjWriter/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

ScriptPath="$(cd "$(dirname "$0")"; pwd -P)"

# Clone the LLVM repo
pushd "$1" || exit 1
if [ ! -d llvm ]; then
git clone -b release_50 https://github.com/llvm-mirror/llvm.git || exit 1
fi

# Clean the tree and apply the patch
cd llvm && git restore . || exit 1
git apply "$ScriptPath/llvm.patch" || exit 1

# Add ObjWriter files
rsync -av --delete "$ScriptPath/" tools/ObjWriter || exit 1

# Configure and build
[ -d build ] || mkdir build
cd build || exit 1

cmake ../ -DCMAKE_BUILD_TYPE=Release -DLLVM_OPTIMIZED_TABLEGEN=1 -DHAVE_POSIX_SPAWN=0 -DLLVM_ENABLE_PIC=1 -DLLVM_BUILD_TESTS=0 -DLLVM_ENABLE_DOXYGEN=0 -DLLVM_INCLUDE_DOCS=0 -DLLVM_INCLUDE_TESTS=0 -DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64" -DCMAKE_INSTALL_PREFIX=install || exit 1
cmake --build . -j 10 --config Release --target install || exit 1
16 changes: 14 additions & 2 deletions src/coreclr/Tools/aot/ObjWriter/llvm.patch
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ index 2bd0cbf9f7c..e7643d5f66d 100644
+ .Case("R_AARCH64_JUMP26", (MCFixupKind)AArch64::fixup_aarch64_pcrel_call26)
+ .Case("R_AARCH64_ADR_PREL_LO21",(MCFixupKind)AArch64::fixup_aarch64_pcrel_adrp_imm21)
+ .Case("R_AARCH64_ADD_ABS_LO12_NC", (MCFixupKind)AArch64::fixup_aarch64_add_imm12)
+ .Default(MCAsmBackend::getFixupKind(Name));
+ .Default(MCAsmBackend::getFixupKind(Name));
+ }
+
+
+
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override {
const static MCFixupKindInfo Infos[AArch64::NumTargetFixupKinds] = {
Expand Down Expand Up @@ -127,6 +127,18 @@ index 89c3e5b4c76..ba105365d74 100644
return R_CLS(PREL32);
case FK_Data_8:
if (IsILP32) {
diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
index 31762b9e4cd..5d8c6d89efc 100644
--- a/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
+++ b/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
@@ -53,6 +53,7 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
}

case FK_Data_4:
+ case FK_PCRel_4:
switch (Modifier) {
default:
return COFF::IMAGE_REL_ARM64_ADDR32;
diff --git a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index a77df7a2598..e1aa7526f9b 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/Tools/aot/ObjWriter/objwriter.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<BuildScriptName Condition="'$(TargetOS)' == 'windows'">build.cmd</BuildScriptName>
<BuildScriptName Condition="'$(TargetOS)' != 'windows'">build.sh</BuildScriptName>
</PropertyGroup>

<Target Name="Build">
<!-- Use IgnoreStandardErrorWarningFormat because Arcade sets WarnAsError and there are multiple warnings in the LLVM build -->
<Exec Command="$(BuildScriptName) $(ArtifactsDir)"
IgnoreStandardErrorWarningFormat="true" />
</Target>
</Project>

0 comments on commit 04aba0b

Please sign in to comment.