Switch to objwriter from the dotnet/llvm-project repo (#63177)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Fri, 31 Dec 2021 04:34:33 +0000 (13:34 +0900)
committerGitHub <noreply@github.com>
Fri, 31 Dec 2021 04:34:33 +0000 (13:34 +0900)
29 files changed:
NuGet.config
docs/design/coreclr/botr/ilc-architecture.md
docs/workflow/building/coreclr/nativeaot.md
docs/workflow/debugging/coreclr/debugging-aot-compilers.md
eng/Subsets.props
eng/Version.Details.xml
eng/Versions.props
src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj
src/coreclr/tools/aot/ObjWriter/.editorconfig [deleted file]
src/coreclr/tools/aot/ObjWriter/CMakeLists.txt [deleted file]
src/coreclr/tools/aot/ObjWriter/README.md [deleted file]
src/coreclr/tools/aot/ObjWriter/build.cmd [deleted file]
src/coreclr/tools/aot/ObjWriter/build.sh [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/codeView/codeViewTypeBuilder.cpp [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/codeView/codeViewTypeBuilder.h [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfAbbrev.cpp [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfAbbrev.h [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfGen.cpp [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfGen.h [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfTypeBuilder.cpp [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfTypeBuilder.h [deleted file]
src/coreclr/tools/aot/ObjWriter/debugInfo/typeBuilder.h [deleted file]
src/coreclr/tools/aot/ObjWriter/jitDebugInfo.h [deleted file]
src/coreclr/tools/aot/ObjWriter/llvm.patch [deleted file]
src/coreclr/tools/aot/ObjWriter/objwriter.cpp [deleted file]
src/coreclr/tools/aot/ObjWriter/objwriter.exports [deleted file]
src/coreclr/tools/aot/ObjWriter/objwriter.h [deleted file]
src/coreclr/tools/aot/ObjWriter/objwriter.proj [deleted file]
src/coreclr/tools/aot/ObjWriter/toolchain.cmake [deleted file]

index 8d59f27..f74e0c4 100644 (file)
@@ -22,8 +22,6 @@
     <add key="dotnet6-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6-transport/nuget/v3/index.json" />
     <!-- Used for the Rich Navigation indexing task -->
     <add key="richnav" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-buildservices/nuget/v3/index.json" />
-    <!-- Used for NativeAOT ObjWriter. TODO: Delete once we publish the package from here. -->
-    <add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
   </packageSources>
   <disabledPackageSources>
     <clear />
index 697f2b7..6f27769 100644 (file)
@@ -139,7 +139,7 @@ While the object file format is highly target specific, the compiler represents
 On a high level, the role of the object writer is to go over all the marked `ObjectNode`s in the graph, retrieve their data, defined symbols, and relocations to other symbols, and store them in the object file.
 
 NativeAOT compiler contains multiple object writers:
-* Native object writer (`src/coreclr/tools/aot/ObjWriter`) based on LLVM that is capable of producing Windows PE, Linux ELF, and macOS Mach-O file formats
+* Native object writer based on LLVM that is capable of producing Windows PE, Linux ELF, and macOS Mach-O file formats
 * Native object writer based on LLVM for WebAssembly
 * Ready to run object writer that generates mixed CIL/native executables in the ready to run format for CoreCLR
 
index 576939f..968bb5f 100644 (file)
@@ -25,7 +25,7 @@ The executable looks like a native executable, in the sense that it can be debug
 - [NOT PORTED OVER YET] The build will place the toolchain packages at `artifacts\packages\[Debug|Release]\Shipping`. To publish your project using these packages:
    - [NOT PORTED OVER YET] Add the package directory to your `nuget.config` file. For example, replace `dotnet-experimental` line in `samples\HelloWorld\nuget.config` with `<add key="local" value="C:\runtimelab\artifacts\packages\Debug\Shipping" />`
    - [NOT PORTED OVER YET] Run `dotnet publish --packages pkg -r [win-x64|linux-x64|osx-64] -c [Debug|Release]` to publish your project. `--packages pkg` option restores the package into a local directory that is easy to cleanup once you are done. It avoids polluting the global nuget cache with your locally built dev package.
-- *Optional*. The ObjWriter component of the AOT compiler is not built by default. If you're working on ObjWriter or bringing up a new platform that doesn't have ObjWriter packages yet, as additional pre-requiresites you need to run `build[.cmd|.sh] clr.objwriter` from the repo root before building the product.
+- The component that writes out object files (objwriter.dll/libobjwriter.so/libobjwriter.dylib) is based on LLVM and doesn't build in the runtime repo. It gets published as a NuGet package out of the dotnet/llvm-project repo (branch objwriter/12.x). If you're working on ObjWriter or bringing up a new platform that doesn't have ObjWriter packages yet, as additional pre-requiresites you need to build objwriter out of that repo and replace the file in the output.
 
 ## Visual Studio Solutions
 
index e2fd7f7..048d571 100644 (file)
@@ -81,7 +81,7 @@ At the time of writing the current supported sets of valid arguments are:
 
 - The ILC compiler typically compiles the whole program - it loosely corresponds to the composite mode of crossgen2. There is a multifile mode, where each managed assembly corresponds to a single object file, but this mode is not shipping.
 
-- The object files generated by the ILC compiler are written out using an LLVM-based object writer (src\coreclr\tools\aot\ObjWriter). The object writer uses the LLVM assembler APIs (APIs meant to be used by tools that convert textual assembly into machine code) to emit object files in PE/ELF/Mach-O formats. Normally the object writer is not built as part of the repo, but gets downloaded through NuGet. If you need to debug the object writer, you can build it by specifying `clr.objwriter` subset to the root build script. It takes about 5 minutes to compile the object writer.
+- The object files generated by the ILC compiler are written out using an LLVM-based object writer (consumed as a NuGet package built out of the dotnet/llvm-project repo, branch objwriter/12.x). The object writer uses the LLVM assembler APIs (APIs meant to be used by tools that convert textual assembly into machine code) to emit object files in PE/ELF/Mach-O formats.
 
 Example of debugging a test application in Crossgen2
 ================================================
index 05470bc..21fea1e 100644 (file)
@@ -51,7 +51,7 @@
 
   <PropertyGroup>
     <!-- CLR NativeAot only builds in a subset of the matrix -->
-    <NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'OSX') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64') and ('$(TargetOS)' != 'OSX' or '$(TargetArchitecture)' != 'arm64') and ('$(__DistroRid)' != 'linux-musl-arm64')">true</NativeAotSupported>
+    <NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'OSX') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64') and ('$(TargetOS)' != 'OSX' or '$(TargetArchitecture)' != 'arm64')">true</NativeAotSupported>
 
     <!-- If we're building clr.nativeaotlibs and not building the CLR runtime, compile libraries against NativeAOT CoreLib -->
     <UseNativeAotCoreLib Condition="$(_subset.Contains('+clr.nativeaotlibs+')) and !$(_subset.Contains('+clr+')) and !$(_subset.Contains('+clr.runtime+'))">true</UseNativeAotCoreLib>
     <SubsetName Include="Clr.Runtime" Description="The CoreCLR .NET runtime." />
     <SubsetName Include="Clr.Native" Description="All CoreCLR native non-test components, including the runtime, jits, and other native tools." />
     <SubsetName Include="Clr.NativeAotLibs" Description="The CoreCLR native AOT CoreLib, runtime, and other low level class libraries." />
-    <SubsetName Include="Clr.ObjWriter" Description="Object writer for the CoreCLR Native AOT compiler." />
     <SubsetName Include="Clr.PalTests" OnDemand="true" Description="The CoreCLR PAL tests." />
     <SubsetName Include="Clr.PalTestList" OnDemand="true" Description="Generate the list of the CoreCLR PAL tests. When using the command line, use Clr.PalTests instead." />
     <SubsetName Include="Clr.Hosts" Description="The CoreCLR corerun test host." />
     <ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\**\src\*.csproj" Category="clr" />
   </ItemGroup>
 
-  <ItemGroup Condition="$(_subset.Contains('+clr.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)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator' or '$(TargetOS)' == 'MacCatalyst' or '$(TargetOS)' == 'Android' or '$(TargetOS)' == 'Browser'">
     <ProjectToBuild Include="$(MonoProjectRoot)llvm\llvm-init.proj" Category="mono" />
index bb600ce..e3a571f 100644 (file)
       <Uri>https://github.com/dotnet/wcf</Uri>
       <Sha>7f504aabb1988e9a093c1e74d8040bd52feb2f01</Sha>
     </Dependency>
+    <Dependency Name="runtime.linux-arm64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.linux-x64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.linux-musl-x64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.win-arm64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.win-x64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.osx.11.0-arm64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
+    <Dependency Name="runtime.osx.10.12-x64.Microsoft.NETCore.Runtime.ObjWriter" Version="1.0.0-alpha.1.21630.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>ef5d90bc37b53288e32d78dbf34eae32cd0893d3</Sha>
+    </Dependency>
   </ProductDependencies>
   <ToolsetDependencies>
     <Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="7.0.0-beta.21621.3">
index d284110..47d31b3 100644 (file)
     <MicrosoftExtensionsDependencyModelVersion>3.1.0</MicrosoftExtensionsDependencyModelVersion>
     <!-- CoreClr dependencies -->
     <MicrosoftNETCoreILAsmVersion>7.0.0-alpha.1.21620.1</MicrosoftNETCoreILAsmVersion>
+    <runtimelinuxarm64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimelinuxarm64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimelinuxx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimelinuxx64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimelinuxmuslarm64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimelinuxmuslarm64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimelinuxmuslx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimelinuxmuslx64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimewinarm64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimewinarm64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion>
+    <runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.21630.1</runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion>
     <!-- Libraries dependencies -->
     <MicrosoftBclAsyncInterfacesVersion>5.0.0</MicrosoftBclAsyncInterfacesVersion>
     <MicrosoftWin32PrimitivesVersion>4.3.0</MicrosoftWin32PrimitivesVersion>
index 359af24..5dbe5c2 100644 (file)
   </PropertyGroup>
 
   <PropertyGroup>
-    <ILCompilerVersion>7.0.0-alpha.1.21612.2</ILCompilerVersion>
-
-    <ObjWriterBuildType>$(Configuration)</ObjWriterBuildType>
-    <ObjWriterBuildType Condition="'$(ObjWriterBuildType)' == 'Checked'">Debug</ObjWriterBuildType>
-
-    <ObjWriterArtifactPath Condition="'$(TargetsWindows)' == 'true'">$(ArtifactsDir)llvm-project\llvm\build\$(TargetArchitecture)\$(ObjWriterBuildType)\bin\$(LibPrefix)objwriter$(LibSuffix)</ObjWriterArtifactPath>
-    <ObjWriterArtifactPath Condition="'$(TargetsWindows)' != 'true'">$(ArtifactsDir)llvm-project\llvm\build\$(TargetArchitecture)\lib\$(LibPrefix)objwriter$(LibSuffix)</ObjWriterArtifactPath>
+    <ObjWriterRid Condition="'$(ObjWriterRid)' == '' and '$(RuntimeIdentifier)' == 'osx-x64'">osx.10.12-x64</ObjWriterRid>
+    <ObjWriterRid Condition="'$(ObjWriterRid)' == '' and '$(RuntimeIdentifier)' == 'osx-arm64'">osx.11.0-arm64</ObjWriterRid>
+    <ObjWriterRid Condition="'$(ObjWriterRid)' == ''">$(RuntimeIdentifier)</ObjWriterRid>
+
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'linux-arm64'">$(runtimelinuxarm64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'linux-x64'">$(runtimelinuxx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'linux-musl-arm64'">$(runtimelinuxmuslarm64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'linux-musl-x64'">$(runtimelinuxmuslx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'win-arm64'">$(runtimewinarm64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'win-x64'">$(runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'osx-arm64'">$(runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
+    <ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(RuntimeIdentifier)' == 'osx-x64'">$(runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
 
     <!-- CoreDisTools are used in debugging visualizers. -->
     <IncludeCoreDisTools Condition="'$(Configuration)' != 'Release'">true</IncludeCoreDisTools>
 
   <Import Project="$(RepositoryEngineeringDir)coredistools.targets" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(IncludeCoreDisTools)' == 'true'" />
 
-  <ItemGroup Condition="Exists('$(ObjWriterArtifactPath)')">
-    <Content Include="$(ObjWriterArtifactPath)">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-      <Visible>false</Visible>
-      <Pack>false</Pack>
-    </Content>
-  </ItemGroup>
-
-  <ItemGroup Condition="!Exists('$(ObjWriterArtifactPath)')">
-    <PackageReference Include="Microsoft.DotNet.ILCompiler">
-      <Version>$(ILCompilerVersion)</Version>
+  <ItemGroup>
+    <PackageReference Include="runtime.$(ObjWriterRid).Microsoft.NETCore.Runtime.ObjWriter">
+      <Version>$(ObjWriterVersion)</Version>
     </PackageReference>
 
-    <Content Include="$(NuGetPackageRoot)runtime.$(RuntimeIdentifier).microsoft.dotnet.ilcompiler\$(ILCompilerVersion)\tools\$(LibPrefix)objwriter$(LibSuffix)">
+    <Content Include="$(NuGetPackageRoot)runtime.$(ObjWriterRid).microsoft.netcore.runtime.objwriter\$(ObjWriterVersion)\runtimes\$(ObjWriterRid)\native\$(LibPrefix)objwriter$(LibSuffix)">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
       <Visible>false</Visible>
       <Pack>false</Pack>
diff --git a/src/coreclr/tools/aot/ObjWriter/.editorconfig b/src/coreclr/tools/aot/ObjWriter/.editorconfig
deleted file mode 100644 (file)
index 0c59ada..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-[*.{cpp,h}]
-
-indent_size = 2
diff --git a/src/coreclr/tools/aot/ObjWriter/CMakeLists.txt b/src/coreclr/tools/aot/ObjWriter/CMakeLists.txt
deleted file mode 100644 (file)
index 2c55045..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/objwriter.exports)
-
-set(LLVM_LINK_COMPONENTS
-  AllTargetsDescs
-  AllTargetsInfos
-  MC
-  Support
-  )
-
-message(STATUS "ObjWriter configuring with (${CMAKE_BUILD_TYPE}) build type and (${LLVM_DEFAULT_TARGET_TRIPLE}) default target triple")
-
-include_directories(${CORECLR_INCLUDE_DIR})
-
-add_llvm_library(objwriter SHARED
-  objwriter.cpp
-  debugInfo/codeView/codeViewTypeBuilder.cpp
-  debugInfo/codeView/codeViewTypeBuilder.h
-  debugInfo/dwarf/dwarfTypeBuilder.cpp
-  debugInfo/dwarf/dwarfTypeBuilder.h
-  debugInfo/dwarf/dwarfGen.cpp
-  debugInfo/dwarf/dwarfGen.h
-  debugInfo/dwarf/dwarfAbbrev.cpp
-  debugInfo/dwarf/dwarfAbbrev.h
-  debugInfo/typeBuilder.h
-  objwriter.h # Visual Studio generator doesn't include necessary header files into the project automatically
-)
diff --git a/src/coreclr/tools/aot/ObjWriter/README.md b/src/coreclr/tools/aot/ObjWriter/README.md
deleted file mode 100644 (file)
index af1d3ef..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# Native Object Writer library
-
-This directory contains a native object file writer library based on LLVM. This library exposes C APIs to emit ELF/Mach-O/PE object files.
-
-The implementation is based on LLVM's assembler APIs - these are APIs intended to be consumed by assembly language compilers and are therefore close to the underlying object file formats. When in doubt, look at how the assemblers (e.g. llvm-ml in the tools directory of LLVM) use these APIs.
-
-The build script clones the appropriate version of the LLVM source tree, applies a patch that adds a couple of things we need, and builds the repo with this directory added as an out-of-tree tool.
diff --git a/src/coreclr/tools/aot/ObjWriter/build.cmd b/src/coreclr/tools/aot/ObjWriter/build.cmd
deleted file mode 100644 (file)
index 77cbc45..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-@echo off
-setlocal
-
-set "ScriptDir=%~dp0"
-set "ArtifactsDir=%~1"
-set "RepoRoot=%~2"
-set "BuildArch=%~3"
-set "TargetArch=%~4"
-set "BuildType=%~5"
-if "%BuildType%"=="" set "BuildType=Release"
-
-set LLVMBranch=release/12.x
-
-:: Check that we have enough arguments
-if "%TargetArch%"=="" (
-    echo Usage: %~nx0 ArtifactsDir RepoRoot BuildArch TargetArch [BuildType]
-    goto Error
-)
-
-cd "%ArtifactsDir%" || goto Error
-
-if not exist llvm-project (
-    rem Clone the LLVM repo
-    git clone --no-checkout --depth 1 -b %LLVMBranch% https://github.com/llvm/llvm-project.git || goto Error
-    cd llvm-project || goto Error
-    :: Purposefuly ignoring exit codes of sparse-checkout so that this works with git lower than 2.26
-    git sparse-checkout init
-    git sparse-checkout set /llvm/* !/llvm/test/*
-    git checkout %LLVMBranch% || goto Error
-    cd llvm || goto Error
-    goto ApplyPatch
-)
-
-:: Check whether the current diff is the same as the patch
-cd llvm-project\llvm || goto Error
-if not exist build mkdir build
-set "DiffFile=build\llvm_%RANDOM%.patch"
-git diff --full-index >"%DiffFile%" || goto Error
-fc "%DiffFile%" "%ScriptDir%llvm.patch"
-if %ErrorLevel% == 0 (
-    rem The current diff is the same as the patch
-    del "%DiffFile%"
-    goto PatchApplied
-) else (
-    echo LLVM changes are saved to %CD%/%DiffFile% and overwritten with %ScriptDir%llvm.patch
-)
-
-:ApplyPatch
-
-:: Clean the tree and apply the patch
-git restore . || goto Error
-git apply "%ScriptDir%llvm.patch" || goto Error
-
-:PatchApplied
-
-:: Init VS environment
-call "%RepoRoot%eng\native\init-vs-env.cmd" || goto Error
-
-:: Set CMakePath by evaluating the output from set-cmake-path.ps1
-for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%RepoRoot%eng\native\set-cmake-path.ps1"""') do %%a
-echo Using CMake at "%CMakePath%"
-
-:: Configure and build objwriter
-if /i "%BuildArch%"=="%TargetArch%" (
-    call :BuildLlvmTarget objwriter "%TargetArch%" || goto Error
-    exit /b 0
-)
-
-rem Cross-build: first build llvm-tblgen.exe for the build architecture
-set "TableGen=%CD%\build\%BuildArch%\%BuildType%\bin\llvm-tblgen.exe"
-
-if not exist "%TableGen%" (
-    echo Building llvm-tablegen.exe
-    call :BuildLlvmTarget llvm-tblgen "%BuildArch%" || goto Error
-    if not exist "%TableGen%" goto Error
-)
-
-rem Now use llvm-tblgen.exe to build objwriter for the target architecture
-set "CMakeArch=%TargetArch%"
-if /i "%TargetArch%"=="x86" set "CMakeArch=Win32"
-
-call :BuildLlvmTarget objwriter "%TargetArch%" "-A %CMakeArch% -DLLVM_TABLEGEN=%TableGen%" || goto Error
-exit /b 0
-
-:BuildLlvmTarget
-set "Target=%~1"
-set "Arch=%~2"
-set "ExtraCMakeArgs=%~3"
-
-"%CMakePath%" -S . -B "build\%Arch%" ^
-    %ExtraCMakeArgs% ^
-    -DCMAKE_TOOLCHAIN_FILE="%ScriptDir%toolchain.cmake" ^
-    -DCMAKE_BUILD_TYPE=%BuildType% ^
-    -DCMAKE_INSTALL_PREFIX=install ^
-    -DLLVM_BUILD_TOOLS=0 ^
-    -DLLVM_ENABLE_TERMINFO=0 ^
-    -DLLVM_INCLUDE_UTILS=0 ^
-    -DLLVM_INCLUDE_RUNTIMES=0 ^
-    -DLLVM_INCLUDE_EXAMPLES=0 ^
-    -DLLVM_INCLUDE_TESTS=0 ^
-    -DLLVM_INCLUDE_DOCS=0 ^
-    -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" ^
-    -DLLVM_EXTERNAL_OBJWRITER_SOURCE_DIR="%ScriptDir%\" ^
-    -DCORECLR_INCLUDE_DIR="%RepoRoot%src\coreclr\inc" ^
-    || goto Error
-
-echo Executing "%CMakePath%" --build "build\%Arch%" --config %BuildType% --target %Target% -- -m
-"%CMakePath%" --build "build\%Arch%" --config %BuildType% --target %Target% -- -m || goto Error
-echo Done building target %Target%
-exit /b 0
-
-:Error
-exit /b 1
diff --git a/src/coreclr/tools/aot/ObjWriter/build.sh b/src/coreclr/tools/aot/ObjWriter/build.sh
deleted file mode 100644 (file)
index 00aeea9..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/env bash
-
-ScriptDir="$(cd "$(dirname "$0")"; pwd -P)"
-ArtifactsDir="$1"
-RepoRoot="$2"
-BuildArch="$3"
-TargetArch="$4"
-BuildType="${5:-Release}"
-Compiler="$(echo "$6" | tr "[:upper:]" "[:lower:]")"
-Compiler="${Compiler:-clang}"
-
-LLVMBranch="release/12.x"
-
-# Check that we have enough arguments
-if [ $# -lt 4 ]; then
-    echo "Usage: $(basename $0) ArtifactsDir RepoRoot BuildArch TargetArch [BuildType [CompilerId]]"
-    exit 1
-fi
-
-cd "$ArtifactsDir" || exit 1
-PatchApplied=0
-
-if [ ! -d llvm-project ]; then
-    # Clone the LLVM repo
-    git clone --no-checkout --depth 1 -b $LLVMBranch https://github.com/llvm/llvm-project.git || exit 1
-    cd llvm-project || exit 1
-    # Purposefuly ignoring exit codes of sparse-checkout so that this works with git lower than 2.26
-    git sparse-checkout init
-    git sparse-checkout set /llvm/\* !/llvm/test/\*
-    git checkout $LLVMBranch || exit 1
-    cd llvm || exit 1
-else
-    # Check whether the current diff is the same as the patch
-    cd llvm-project/llvm || exit 1
-    mkdir -p build
-    DiffFile="build/llvm_$RANDOM.patch"
-    git diff --full-index >"$DiffFile" || exit 1
-    cmp -s "$DiffFile" "$ScriptDir/llvm.patch"
-    if [ $? -eq 0 ]; then
-        # The current diff is the same as the patch
-        rm "$DiffFile"
-        PatchApplied=1
-    else
-        echo "LLVM changes are saved to $PWD/$DiffFile and overwritten with $ScriptDir/llvm.patch"
-    fi
-fi
-
-if [ "$PatchApplied" -ne 1 ]; then
-    # Clean the tree and apply the patch
-    git checkout -- . || exit 1
-    git apply "$ScriptDir/llvm.patch" || exit 1
-fi
-
-# Configure and build objwriter
-mkdir -p "build/$TargetArch" || exit 1
-
-if [ "$TargetArch" != "$BuildArch" ]; then
-    export CROSSCOMPILE=1
-fi
-
-# Script arguments:
-#   <path to top-level CMakeLists.txt> <path to intermediate directory> <architecture>
-#   <compiler> <compiler major version> <compiler minor version>
-#   [build flavor] [ninja] [scan-build] [cmakeargs]
-"${RepoRoot}eng/native/gen-buildsys.sh" \
-    "$PWD" "$PWD/build/$TargetArch" "$TargetArch" \
-    "$Compiler" "$BuildType" \
-    -DCMAKE_BUILD_TYPE="$BuildType" \
-    -DCMAKE_INSTALL_PREFIX=install \
-    -DLLVM_BUILD_TOOLS=0 \
-    -DLLVM_ENABLE_TERMINFO=0 \
-    -DLLVM_INCLUDE_UTILS=0 \
-    -DLLVM_INCLUDE_RUNTIMES=0 \
-    -DLLVM_INCLUDE_EXAMPLES=0 \
-    -DLLVM_INCLUDE_TESTS=0 \
-    -DLLVM_INCLUDE_DOCS=0 \
-    -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" \
-    -DLLVM_EXTERNAL_OBJWRITER_SOURCE_DIR="$ScriptDir" \
-    -DCORECLR_INCLUDE_DIR="${RepoRoot}src/coreclr/inc" \
-    || exit 1
-
-# Get the number of available processors
-Platform="$(uname)"
-if [[ "$Platform" == "FreeBSD" ]]; then
-    NumProc=$(sysctl -n hw.ncpu)
-elif [[ "$Platform" == "NetBSD" || "$Platform" == "SunOS" ]]; then
-    NumProc=$(getconf NPROCESSORS_ONLN)
-elif [[ "$Platform" == "Darwin" ]]; then
-    NumProc=$(getconf _NPROCESSORS_ONLN)
-else
-    NumProc=$(nproc --all)
-fi
-
-MaxJobs=$((NumProc+1))
-
-echo "Executing cmake --build \"build/$TargetArch\" --config \"$BuildType\" --target objwriter -j \"$MaxJobs\""
-cmake --build "build/$TargetArch" --config "$BuildType" --target objwriter -j "$MaxJobs" || exit 1
-echo "Done building target objwriter"
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/codeView/codeViewTypeBuilder.cpp b/src/coreclr/tools/aot/ObjWriter/debugInfo/codeView/codeViewTypeBuilder.cpp
deleted file mode 100644 (file)
index de90c53..0000000
+++ /dev/null
@@ -1,344 +0,0 @@
-//===---- codeViewTypeBuilder.cpp -------------------------------*- C++ -*-===//
-//
-// type builder implementation using codeview::TypeTableBuilder
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#include "codeViewTypeBuilder.h"
-#include "llvm/BinaryFormat/COFF.h"
-#include <sstream>
-#include <vector>
-
-UserDefinedCodeViewTypesBuilder::UserDefinedCodeViewTypesBuilder()
-    : Allocator(), TypeTable(Allocator)
-{
-    // We pretend that the MethodTable pointer in System.Object is VTable shape.
-    // We use the same "Vtable" for all types because the vtable shape debug
-    // record is not expressive enough to capture our vtable shape (where the
-    // vtable slots don't start at the beginning of the vtable).
-    VFTableShapeRecord vfTableShape(TypeRecordKind::VFTableShape);
-    ClassVTableTypeIndex = TypeTable.writeLeafType(vfTableShape);
-
-    PointerRecord ptrToVfTableShape(ClassVTableTypeIndex,
-        TargetPointerSize == 8 ? PointerKind::Near64 : PointerKind::Near32,
-        PointerMode::LValueReference,
-        PointerOptions::None,
-        0);
-
-    VFuncTabTypeIndex = TypeTable.writeLeafType(ptrToVfTableShape);
-}
-
-void UserDefinedCodeViewTypesBuilder::EmitCodeViewMagicVersion() {
-  Streamer->emitValueToAlignment(4);
-  Streamer->AddComment("Debug section magic");
-  Streamer->emitIntValue(COFF::DEBUG_SECTION_MAGIC, 4);
-}
-
-ClassOptions UserDefinedCodeViewTypesBuilder::GetCommonClassOptions() {
-  return ClassOptions();
-}
-
-void UserDefinedCodeViewTypesBuilder::EmitTypeInformation(
-    MCSection *TypeSection,
-    MCSection *StrSection) {
-
-  if (TypeTable.empty())
-    return;
-
-  Streamer->SwitchSection(TypeSection);
-  EmitCodeViewMagicVersion();
-
-  TypeTable.ForEachRecord([&](TypeIndex FieldTypeIndex,
-                              CVRecord<TypeLeafKind> Record) {
-    StringRef S(reinterpret_cast<const char *>(Record.data().data()), Record.data().size());
-    Streamer->emitBinaryData(S);
-  });
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetEnumFieldListType(
-    uint64 Count, const EnumRecordTypeDescriptor *TypeRecords) {
-  ContinuationRecordBuilder CRB;
-  CRB.begin(ContinuationRecordKind::FieldList);
-#ifndef NDEBUG
-  uint64 MaxInt = (unsigned int)-1;
-  assert(Count <= MaxInt && "There are too many fields inside enum");
-#endif
-  for (int i = 0; i < (int)Count; ++i) {
-    EnumRecordTypeDescriptor record = TypeRecords[i];
-    EnumeratorRecord ER(MemberAccess::Public, APSInt::getUnsigned(record.Value),
-                        record.Name);
-    CRB.writeMemberType(ER);
-  }
-  return TypeTable.insertRecord(CRB).getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetEnumTypeIndex(
-    const EnumTypeDescriptor &TypeDescriptor,
-    const EnumRecordTypeDescriptor *TypeRecords) {
-
-  ClassOptions CO = GetCommonClassOptions();
-  unsigned FieldListIndex =
-      GetEnumFieldListType(TypeDescriptor.ElementCount, TypeRecords);
-  TypeIndex FieldListIndexType = TypeIndex(FieldListIndex);
-  TypeIndex ElementTypeIndex = TypeIndex(TypeDescriptor.ElementType);
-
-  EnumRecord EnumRecord(TypeDescriptor.ElementCount, CO, FieldListIndexType,
-                        TypeDescriptor.Name, StringRef(),
-                        ElementTypeIndex);
-
-  TypeIndex Type = TypeTable.writeLeafType(EnumRecord);
-  UserDefinedTypes.push_back(std::make_pair(TypeDescriptor.Name, Type.getIndex()));
-  return Type.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetClassTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor) {
-  TypeRecordKind Kind =
-      ClassDescriptor.IsStruct ? TypeRecordKind::Struct : TypeRecordKind::Class;
-  ClassOptions CO = ClassOptions::ForwardReference | GetCommonClassOptions();
-
-  ClassRecord CR(Kind, 0, CO, TypeIndex(), TypeIndex(), TypeIndex(), 0,
-                 ClassDescriptor.Name, StringRef());
-  TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR);
-  return FwdDeclTI.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetCompleteClassTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor,
-    const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-    const DataFieldDescriptor *FieldsDescriptors,
-    const StaticDataFieldDescriptor *StaticsDescriptors) {
-
-  ContinuationRecordBuilder CRB;
-  CRB.begin(ContinuationRecordKind::FieldList);
-
-  uint16_t memberCount = 0;
-  if (ClassDescriptor.BaseClassId != 0) {
-    memberCount++;
-    AddBaseClass(CRB, ClassDescriptor.BaseClassId);
-  }
-  else if (!ClassDescriptor.IsStruct) {
-    memberCount++;
-    AddClassVTShape(CRB);
-  }
-
-  for (int i = 0; i < ClassFieldsDescriptor.FieldsCount; ++i) {
-    DataFieldDescriptor desc = FieldsDescriptors[i];
-    MemberAccess Access = MemberAccess::Public;
-    TypeIndex MemberBaseType(desc.FieldTypeIndex);
-    if (desc.Offset == 0xFFFFFFFF)
-    {
-      StaticDataMemberRecord SDMR(Access, MemberBaseType, desc.Name);
-      CRB.writeMemberType(SDMR);
-    }
-    else
-    {
-      int MemberOffsetInBytes = desc.Offset;
-      DataMemberRecord DMR(Access, MemberBaseType, MemberOffsetInBytes,
-          desc.Name);
-      CRB.writeMemberType(DMR);
-    }
-    memberCount++;
-  }
-  TypeIndex FieldListIndex = TypeTable.insertRecord(CRB);
-  TypeRecordKind Kind =
-      ClassDescriptor.IsStruct ? TypeRecordKind::Struct : TypeRecordKind::Class;
-  ClassOptions CO = GetCommonClassOptions();
-  ClassRecord CR(Kind, memberCount, CO, FieldListIndex,
-                 TypeIndex(), TypeIndex(), ClassFieldsDescriptor.Size,
-                 ClassDescriptor.Name, StringRef());
-  TypeIndex ClassIndex = TypeTable.writeLeafType(CR);
-
-  UserDefinedTypes.push_back(std::make_pair(ClassDescriptor.Name, ClassIndex.getIndex()));
-
-  return ClassIndex.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetArrayTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor,
-    const ArrayTypeDescriptor &ArrayDescriptor) {
-  ContinuationRecordBuilder CRB;
-  CRB.begin(ContinuationRecordKind::FieldList);
-
-  unsigned Offset = 0;
-  unsigned FieldsCount = 0;
-
-  assert(ClassDescriptor.BaseClassId != 0);
-
-  AddBaseClass(CRB, ClassDescriptor.BaseClassId);
-  FieldsCount++;
-  Offset += TargetPointerSize;
-
-  MemberAccess Access = MemberAccess::Public;
-  TypeIndex IndexType = TypeIndex(SimpleTypeKind::Int32);
-  DataMemberRecord CountDMR(Access, IndexType, Offset, "count");
-  CRB.writeMemberType(CountDMR);
-  FieldsCount++;
-  Offset += TargetPointerSize;
-
-  if (ArrayDescriptor.IsMultiDimensional == 1) {
-    for (unsigned i = 0; i < ArrayDescriptor.Rank; ++i) {
-      DataMemberRecord LengthDMR(Access, TypeIndex(SimpleTypeKind::Int32),
-                                 Offset, ArrayDimentions.GetLengthName(i));
-      CRB.writeMemberType(LengthDMR);
-      FieldsCount++;
-      Offset += 4;
-    }
-
-    for (unsigned i = 0; i < ArrayDescriptor.Rank; ++i) {
-      DataMemberRecord BoundsDMR(Access, TypeIndex(SimpleTypeKind::Int32),
-                                 Offset, ArrayDimentions.GetBoundsName(i));
-      CRB.writeMemberType(BoundsDMR);
-      FieldsCount++;
-      Offset += 4;
-    }
-  }
-
-  TypeIndex ElementTypeIndex = TypeIndex(ArrayDescriptor.ElementType);
-  ArrayRecord AR(ElementTypeIndex, IndexType, ArrayDescriptor.Size, "");
-  TypeIndex ArrayIndex = TypeTable.writeLeafType(AR);
-  DataMemberRecord ArrayDMR(Access, ArrayIndex, Offset, "values");
-  CRB.writeMemberType(ArrayDMR);
-  FieldsCount++;
-
-  TypeIndex FieldListIndex = TypeTable.insertRecord(CRB);
-
-  assert(ClassDescriptor.IsStruct == false);
-  TypeRecordKind Kind = TypeRecordKind::Class;
-  ClassOptions CO = GetCommonClassOptions();
-  ClassRecord CR(Kind, FieldsCount, CO, FieldListIndex, TypeIndex(),
-                 TypeIndex(), ArrayDescriptor.Size, ClassDescriptor.Name,
-                 StringRef());
-  TypeIndex ClassIndex = TypeTable.writeLeafType(CR);
-
-  UserDefinedTypes.push_back(std::make_pair(ClassDescriptor.Name, ClassIndex.getIndex()));
-
-  return ClassIndex.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor)
-{
-    uint32_t elementType = PointerDescriptor.ElementType;
-    PointerKind pointerKind = PointerDescriptor.Is64Bit ? PointerKind::Near64 : PointerKind::Near32;
-    PointerMode pointerMode = PointerDescriptor.IsReference ? PointerMode::LValueReference : PointerMode::Pointer;
-    PointerOptions pointerOptions = PointerDescriptor.IsConst ? PointerOptions::Const : PointerOptions::None;
-
-    PointerRecord PointerToClass(TypeIndex(elementType), pointerKind, pointerMode, pointerOptions, 0);
-    TypeIndex PointerIndex = TypeTable.writeLeafType(PointerToClass);
-    return PointerIndex.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-    uint32_t const *const ArgumentTypes)
-{
-    std::vector<TypeIndex> argumentTypes;
-    argumentTypes.reserve(MemberDescriptor.NumberOfArguments);
-    for (uint16_t iArgument = 0; iArgument < MemberDescriptor.NumberOfArguments; iArgument++)
-    {
-        argumentTypes.emplace_back(ArgumentTypes[iArgument]);
-    }
-
-    ArgListRecord ArgList(TypeRecordKind::ArgList, argumentTypes);
-    TypeIndex ArgumentList = TypeTable.writeLeafType(ArgList);
-
-    MemberFunctionRecord MemberFunction(TypeIndex(MemberDescriptor.ReturnType), 
-                                        TypeIndex(MemberDescriptor.ContainingClass), 
-                                        TypeIndex(MemberDescriptor.TypeIndexOfThisPointer), 
-                                        CallingConvention(MemberDescriptor.CallingConvention), 
-                                        FunctionOptions::None, MemberDescriptor.NumberOfArguments, 
-                                        ArgumentList, 
-                                        MemberDescriptor.ThisAdjust);
-
-    TypeIndex MemberFunctionIndex = TypeTable.writeLeafType(MemberFunction);
-    return MemberFunctionIndex.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor)
-{
-    MemberFuncIdRecord MemberFuncId(TypeIndex(MemberIdDescriptor.MemberFunction), TypeIndex(MemberIdDescriptor.ParentClass), MemberIdDescriptor.Name);
-    TypeIndex MemberFuncIdIndex = TypeTable.writeLeafType(MemberFuncId);
-    return MemberFuncIdIndex.getIndex();
-}
-
-unsigned UserDefinedCodeViewTypesBuilder::GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) {
-  switch (Type) {
-    case PrimitiveTypeFlags::Void:
-      return TypeIndex::Void().getIndex();
-    case PrimitiveTypeFlags::Boolean:
-      return TypeIndex(SimpleTypeKind::Boolean8).getIndex();
-    case PrimitiveTypeFlags::Char:
-      return TypeIndex::WideCharacter().getIndex();
-    case PrimitiveTypeFlags::SByte:
-      return TypeIndex(SimpleTypeKind::SByte).getIndex();
-    case PrimitiveTypeFlags::Byte:
-      return TypeIndex(SimpleTypeKind::Byte).getIndex();
-    case PrimitiveTypeFlags::Int16:
-      return TypeIndex(SimpleTypeKind::Int16).getIndex();
-    case PrimitiveTypeFlags::UInt16:
-      return TypeIndex(SimpleTypeKind::UInt16).getIndex();
-    case PrimitiveTypeFlags::Int32:
-      return TypeIndex::Int32().getIndex();
-    case PrimitiveTypeFlags::UInt32:
-      return TypeIndex::UInt32().getIndex();
-    case PrimitiveTypeFlags::Int64:
-      return TypeIndex::Int64().getIndex();
-    case PrimitiveTypeFlags::UInt64:
-      return TypeIndex::UInt64().getIndex();
-    case PrimitiveTypeFlags::Single:
-      return TypeIndex::Float32().getIndex();
-    case PrimitiveTypeFlags::Double:
-      return TypeIndex::Float64().getIndex();
-    case PrimitiveTypeFlags::IntPtr:
-    case PrimitiveTypeFlags::UIntPtr:
-      return TargetPointerSize == 4 ? TypeIndex::VoidPointer32().getIndex() :
-        TypeIndex::VoidPointer64().getIndex();
-    default:
-      assert(false && "Unexpected type");
-      return 0;
-  }
-}
-
-void UserDefinedCodeViewTypesBuilder::AddBaseClass(ContinuationRecordBuilder &CRB,
-                                           unsigned BaseClassId) {
-  MemberAttributes def;
-  TypeIndex BaseTypeIndex(BaseClassId);
-  BaseClassRecord BCR(def, BaseTypeIndex, 0);
-  CRB.writeMemberType(BCR);
-}
-
-void UserDefinedCodeViewTypesBuilder::AddClassVTShape(ContinuationRecordBuilder &CRB) {
-  VFPtrRecord VfPtr(VFuncTabTypeIndex);
-  CRB.writeMemberType(VfPtr);
-}
-
-const char *ArrayDimensionsDescriptor::GetLengthName(unsigned index) {
-  if (Lengths.size() <= index) {
-    Resize(index + 1);
-  }
-  return Lengths[index].c_str();
-}
-
-const char *ArrayDimensionsDescriptor::GetBoundsName(unsigned index) {
-  if (Bounds.size() <= index) {
-    Resize(index);
-  }
-  return Bounds[index].c_str();
-}
-
-void ArrayDimensionsDescriptor::Resize(unsigned NewSize) {
-  unsigned OldSize = Lengths.size();
-  assert(OldSize == Bounds.size());
-  Lengths.resize(NewSize);
-  Bounds.resize(NewSize);
-  for (unsigned i = OldSize; i < NewSize; ++i) {
-    std::stringstream ss;
-    ss << "length" << i;
-    ss >> Lengths[i];
-    ss.clear();
-    ss << "bounds" << i;
-    ss >> Bounds[i];
-  }
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/codeView/codeViewTypeBuilder.h b/src/coreclr/tools/aot/ObjWriter/debugInfo/codeView/codeViewTypeBuilder.h
deleted file mode 100644 (file)
index 14980fa..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-//===---- codeViewTypeBuilder.h ---------------------------------*- C++ -*-===//
-//
-// type builder is used to convert .Net types into CodeView descriptors.
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#pragma once
-
-#include "debugInfo/typeBuilder.h"
-#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
-#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
-
-#include <vector>
-
-using namespace llvm::codeview;
-
-class ArrayDimensionsDescriptor {
-public:
-  const char *GetLengthName(unsigned index);
-  const char *GetBoundsName(unsigned index);
-
-private:
-  void Resize(unsigned NewSize);
-
-  std::vector<std::string> Lengths;
-  std::vector<std::string> Bounds;
-};
-
-class UserDefinedCodeViewTypesBuilder : public UserDefinedTypesBuilder {
-public:
-  UserDefinedCodeViewTypesBuilder();
-  void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) override;
-
-  unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor,
-                            const EnumRecordTypeDescriptor *TypeRecords) override;
-  unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) override;
-  unsigned GetCompleteClassTypeIndex(
-      const ClassTypeDescriptor &ClassDescriptor,
-      const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-      const DataFieldDescriptor *FieldsDescriptors,
-      const StaticDataFieldDescriptor *StaticsDescriptors) override;
-
-  unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor,
-                             const ArrayTypeDescriptor &ArrayDescriptor) override;
-
-  unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) override;
-
-  unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-      uint32_t const *const ArgumentTypes) override;
-
-  unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) override;
-
-  unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) override;
-
-private:
-  void EmitCodeViewMagicVersion();
-  ClassOptions GetCommonClassOptions();
-
-  unsigned GetEnumFieldListType(uint64 Count,
-                                const EnumRecordTypeDescriptor *TypeRecords);
-
-  void AddBaseClass(ContinuationRecordBuilder &CRB, unsigned BaseClassId);
-  void AddClassVTShape(ContinuationRecordBuilder &CRB);
-
-  BumpPtrAllocator Allocator;
-  GlobalTypeTableBuilder TypeTable;
-
-  ArrayDimensionsDescriptor ArrayDimentions;
-  TypeIndex ClassVTableTypeIndex;
-  TypeIndex VFuncTabTypeIndex;
-};
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfAbbrev.cpp b/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfAbbrev.cpp
deleted file mode 100644 (file)
index 362d5df..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-//===---- dwarfAbbrev.cpp ---------------------------------------*- C++ -*-===//
-//
-// dwarf abbreviations implementation
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#include "dwarfAbbrev.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCObjectFileInfo.h"
-
-namespace DwarfAbbrev {
-
-void Dump(MCObjectStreamer *Streamer, uint16_t DwarfVersion, unsigned TargetPointerSize) {
-  uint16_t DW_FORM_size;
-  switch (TargetPointerSize) {
-    case 1:
-      DW_FORM_size = dwarf::DW_FORM_data1;
-      break;
-    case 2:
-      DW_FORM_size = dwarf::DW_FORM_data2;
-      break;
-    case 4:
-      DW_FORM_size = dwarf::DW_FORM_data4;
-      break;
-    case 8:
-      DW_FORM_size = dwarf::DW_FORM_data8;
-      break;
-    default:
-      assert(false && "Unexpected TargerPointerSize");
-      return;
-  }
-
-  const uint16_t AbbrevTable[] = {
-    CompileUnit,
-        dwarf::DW_TAG_compile_unit, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_producer, dwarf::DW_FORM_string,
-        dwarf::DW_AT_language, dwarf::DW_FORM_data2,
-        dwarf::DW_AT_stmt_list, (DwarfVersion >= 4 ? dwarf::DW_FORM_sec_offset : dwarf::DW_FORM_data4),
-        0, 0,
-
-    BaseType,
-        dwarf::DW_TAG_base_type, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
-        0, 0,
-
-    EnumerationType,
-        dwarf::DW_TAG_enumeration_type, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
-        0, 0,
-
-    Enumerator1,
-        dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_const_value, dwarf::DW_FORM_data1,
-        0, 0,
-
-    Enumerator2,
-        dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_const_value, dwarf::DW_FORM_data2,
-        0, 0,
-
-    Enumerator4,
-        dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_const_value, dwarf::DW_FORM_data4,
-        0, 0,
-
-    Enumerator8,
-        dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_const_value, dwarf::DW_FORM_data8,
-        0, 0,
-
-    TypeDef,
-        dwarf::DW_TAG_typedef, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        0, 0,
-
-    Subprogram,
-        dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-        dwarf::DW_AT_high_pc, DW_FORM_size,
-        dwarf::DW_AT_frame_base, dwarf::DW_FORM_exprloc,
-        dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4,
-        0, 0,
-
-    SubprogramStatic,
-        dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-        dwarf::DW_AT_high_pc, DW_FORM_size,
-        dwarf::DW_AT_frame_base, dwarf::DW_FORM_exprloc,
-        0, 0,
-
-    SubprogramSpec,
-        dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_external, dwarf::DW_FORM_flag_present,
-        dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
-        dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4,
-        0, 0,
-
-    SubprogramStaticSpec,
-        dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_external, dwarf::DW_FORM_flag_present,
-        dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
-        0, 0,
-
-    Variable,
-        dwarf::DW_TAG_variable, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_exprloc,
-        0, 0,
-
-    VariableLoc,
-        dwarf::DW_TAG_variable, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset,
-        0, 0,
-
-    VariableStatic,
-        dwarf::DW_TAG_variable, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_exprloc,
-        0, 0,
-
-    FormalParameter,
-        dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_exprloc,
-        0, 0,
-
-    FormalParameterThis,
-        dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_exprloc,
-        dwarf::DW_AT_artificial, dwarf::DW_FORM_flag_present,
-        0, 0,
-
-    FormalParameterLoc,
-        dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset,
-        0, 0,
-
-    FormalParameterThisLoc,
-        dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset,
-        dwarf::DW_AT_artificial, dwarf::DW_FORM_flag_present,
-        0, 0,
-
-    FormalParameterSpec,
-        dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        0, 0,
-
-    FormalParameterThisSpec,
-        dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_artificial, dwarf::DW_FORM_flag_present,
-        0, 0,
-
-    ClassType,
-        dwarf::DW_TAG_class_type, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_byte_size, dwarf::DW_FORM_data4,
-        0, 0,
-
-    ClassTypeDecl,
-        dwarf::DW_TAG_class_type, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
-        0, 0,
-
-    ClassMember,
-        dwarf::DW_TAG_member, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data4,
-        0, 0,
-
-    ClassMemberStatic,
-        dwarf::DW_TAG_member, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_external, dwarf::DW_FORM_flag_present,
-        dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
-        0, 0,
-
-    PointerType,
-        dwarf::DW_TAG_pointer_type, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
-        0, 0,
-
-    ReferenceType,
-        dwarf::DW_TAG_reference_type, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
-        0, 0,
-
-    ArrayType,
-        dwarf::DW_TAG_array_type, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        0, 0,
-
-    SubrangeType,
-        dwarf::DW_TAG_subrange_type, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_upper_bound, dwarf::DW_FORM_udata,
-        0, 0,
-
-    ClassInheritance,
-        dwarf::DW_TAG_inheritance, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
-        dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
-        0, 0,
-
-    LexicalBlock,
-        dwarf::DW_TAG_lexical_block, dwarf::DW_CHILDREN_yes,
-        dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-        dwarf::DW_AT_high_pc, DW_FORM_size,
-        0, 0,
-
-    TryBlock,
-        dwarf::DW_TAG_try_block, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-        dwarf::DW_AT_high_pc, DW_FORM_size,
-        0, 0,
-
-    CatchBlock,
-        dwarf::DW_TAG_catch_block, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-        dwarf::DW_AT_high_pc, DW_FORM_size,
-        0, 0,
-
-    VoidType,
-        dwarf::DW_TAG_unspecified_type, dwarf::DW_CHILDREN_no,
-        dwarf::DW_AT_name, dwarf::DW_FORM_strp,
-        0, 0,
-
-    VoidPointerType,
-        dwarf::DW_TAG_pointer_type, dwarf::DW_CHILDREN_no,
-        0, 0,
-  };
-
-  MCContext &context = Streamer->getContext();
-  Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
-
-  for (uint16_t e : AbbrevTable) {
-      Streamer->emitULEB128IntValue(e);
-  }
-}
-
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfAbbrev.h b/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfAbbrev.h
deleted file mode 100644 (file)
index 3cd8cea..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-//===---- dwarfAbbrev.h -----------------------------------------*- C++ -*-===//
-//
-// dwarf abbreviations
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#pragma once
-
-#include "llvm/BinaryFormat/Dwarf.h"
-#include "llvm/MC/MCObjectStreamer.h"
-
-using namespace llvm;
-
-namespace DwarfAbbrev {
-
-enum DwarfAbbrev : uint16_t
-{
-  CompileUnit = 0x1,
-  BaseType,
-  EnumerationType,
-  Enumerator1,
-  Enumerator2,
-  Enumerator4,
-  Enumerator8,
-  TypeDef,
-  Subprogram,
-  SubprogramStatic,
-  SubprogramSpec,
-  SubprogramStaticSpec,
-  Variable,
-  VariableLoc,
-  VariableStatic,
-  FormalParameter,
-  FormalParameterThis,
-  FormalParameterLoc,
-  FormalParameterThisLoc,
-  FormalParameterSpec,
-  FormalParameterThisSpec,
-  ClassType,
-  ClassTypeDecl,
-  ClassMember,
-  ClassMemberStatic,
-  PointerType,
-  ReferenceType,
-  ArrayType,
-  SubrangeType,
-  ClassInheritance,
-  LexicalBlock,
-  TryBlock,
-  CatchBlock,
-  VoidType,
-  VoidPointerType,
-};
-
-void Dump(MCObjectStreamer *Streamer, uint16_t DwarfVersion, unsigned TargetPointerSize);
-
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfGen.cpp b/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfGen.cpp
deleted file mode 100644 (file)
index b2ad3f4..0000000
+++ /dev/null
@@ -1,1109 +0,0 @@
-//===---- dwarfGen.cpp ------------------------------------------*- C++ -*-===//
-//
-// dwarf generator implementation
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#include "dwarfGen.h"
-#include "dwarfAbbrev.h"
-
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCObjectFileInfo.h"
-#include "llvm/Support/LEB128.h"
-
-#ifdef FEATURE_LANGID_CS
-#define DW_LANG_MICROSOFT_CSHARP 0x9e57
-#endif
-
-// Keep sync with ICorDebugInfo::RegNum (cordebuginfo.h)
-
-enum class RegNumX86
-{
-  REGNUM_EAX,
-  REGNUM_ECX,
-  REGNUM_EDX,
-  REGNUM_EBX,
-  REGNUM_ESP,
-  REGNUM_EBP,
-  REGNUM_ESI,
-  REGNUM_EDI,
-  REGNUM_COUNT,
-  REGNUM_FP = REGNUM_EBP,
-  REGNUM_SP = REGNUM_ESP
-};
-
-enum class RegNumArm
-{
-  REGNUM_R0,
-  REGNUM_R1,
-  REGNUM_R2,
-  REGNUM_R3,
-  REGNUM_R4,
-  REGNUM_R5,
-  REGNUM_R6,
-  REGNUM_R7,
-  REGNUM_R8,
-  REGNUM_R9,
-  REGNUM_R10,
-  REGNUM_R11,
-  REGNUM_R12,
-  REGNUM_SP,
-  REGNUM_LR,
-  REGNUM_PC,
-  REGNUM_COUNT,
-  REGNUM_FP = REGNUM_R7
-};
-
-enum class RegNumArm64
-{
-  REGNUM_X0,
-  REGNUM_X1,
-  REGNUM_X2,
-  REGNUM_X3,
-  REGNUM_X4,
-  REGNUM_X5,
-  REGNUM_X6,
-  REGNUM_X7,
-  REGNUM_X8,
-  REGNUM_X9,
-  REGNUM_X10,
-  REGNUM_X11,
-  REGNUM_X12,
-  REGNUM_X13,
-  REGNUM_X14,
-  REGNUM_X15,
-  REGNUM_X16,
-  REGNUM_X17,
-  REGNUM_X18,
-  REGNUM_X19,
-  REGNUM_X20,
-  REGNUM_X21,
-  REGNUM_X22,
-  REGNUM_X23,
-  REGNUM_X24,
-  REGNUM_X25,
-  REGNUM_X26,
-  REGNUM_X27,
-  REGNUM_X28,
-  REGNUM_FP,
-  REGNUM_LR,
-  REGNUM_SP,
-  REGNUM_PC,
-  REGNUM_COUNT
-};
-
-enum class RegNumAmd64
-{
-  REGNUM_RAX,
-  REGNUM_RCX,
-  REGNUM_RDX,
-  REGNUM_RBX,
-  REGNUM_RSP,
-  REGNUM_RBP,
-  REGNUM_RSI,
-  REGNUM_RDI,
-  REGNUM_R8,
-  REGNUM_R9,
-  REGNUM_R10,
-  REGNUM_R11,
-  REGNUM_R12,
-  REGNUM_R13,
-  REGNUM_R14,
-  REGNUM_R15,
-  REGNUM_COUNT,
-  REGNUM_SP = REGNUM_RSP,
-  REGNUM_FP = REGNUM_RBP
-};
-
-// Helper routines from lib/MC/MCDwarf.cpp
-static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
-  MCContext &Context = OS.getContext();
-  assert(!isa<MCSymbolRefExpr>(Expr));
-  if (Context.getAsmInfo()->hasAggressiveSymbolFolding())
-    return Expr;
-
-  MCSymbol *ABS = Context.createTempSymbol();
-  OS.emitAssignment(ABS, Expr);
-  return MCSymbolRefExpr::create(ABS, Context);
-}
-
-static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
-  const MCExpr *ABS = forceExpAbs(OS, Value);
-  OS.emitValue(ABS, Size);
-}
-
-static const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS,
-                                           const MCSymbol &Start,
-                                           const MCSymbol &End,
-                                           int IntVal) {
-  MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
-  const MCExpr *Res =
-    MCSymbolRefExpr::create(&End, Variant, MCOS.getContext());
-  const MCExpr *RHS =
-    MCSymbolRefExpr::create(&Start, Variant, MCOS.getContext());
-  const MCExpr *Res1 =
-    MCBinaryExpr::create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext());
-  const MCExpr *Res2 =
-    MCConstantExpr::create(IntVal, MCOS.getContext());
-  const MCExpr *Res3 =
-    MCBinaryExpr::create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext());
-  return Res3;
-}
-
-static int GetDwarfRegNum(Triple::ArchType ArchType, int RegNum) {
-  switch (ArchType) {
-    case Triple::x86:
-      switch (static_cast<RegNumX86>(RegNum)) {
-        case RegNumX86::REGNUM_EAX: return 0;
-        case RegNumX86::REGNUM_ECX: return 1;
-        case RegNumX86::REGNUM_EDX: return 2;
-        case RegNumX86::REGNUM_EBX: return 3;
-        case RegNumX86::REGNUM_ESP: return 4;
-        case RegNumX86::REGNUM_EBP: return 5;
-        case RegNumX86::REGNUM_ESI: return 6;
-        case RegNumX86::REGNUM_EDI: return 7;
-        // fp registers
-        default:
-          return RegNum - static_cast<int>(RegNumX86::REGNUM_COUNT) + 32;
-      }
-    case Triple::arm:   // fall through
-    case Triple::armeb: // fall through
-    case Triple::thumb: // fall through
-    case Triple::thumbeb:
-      switch (static_cast<RegNumArm>(RegNum)) {
-        case RegNumArm::REGNUM_R0:  return 0;
-        case RegNumArm::REGNUM_R1:  return 1;
-        case RegNumArm::REGNUM_R2:  return 2;
-        case RegNumArm::REGNUM_R3:  return 3;
-        case RegNumArm::REGNUM_R4:  return 4;
-        case RegNumArm::REGNUM_R5:  return 5;
-        case RegNumArm::REGNUM_R6:  return 6;
-        case RegNumArm::REGNUM_R7:  return 7;
-        case RegNumArm::REGNUM_R8:  return 8;
-        case RegNumArm::REGNUM_R9:  return 9;
-        case RegNumArm::REGNUM_R10: return 10;
-        case RegNumArm::REGNUM_R11: return 11;
-        case RegNumArm::REGNUM_R12: return 12;
-        case RegNumArm::REGNUM_SP:  return 13;
-        case RegNumArm::REGNUM_LR:  return 14;
-        case RegNumArm::REGNUM_PC:  return 15;
-        // fp registers
-        default:
-          return (RegNum - static_cast<int>(RegNumArm::REGNUM_COUNT)) / 2 + 256;
-      }
-    case Triple::aarch64: // fall through
-    case Triple::aarch64_be:
-      switch (static_cast<RegNumArm64>(RegNum)) {
-        case RegNumArm64::REGNUM_X0:  return 0;
-        case RegNumArm64::REGNUM_X1:  return 1;
-        case RegNumArm64::REGNUM_X2:  return 2;
-        case RegNumArm64::REGNUM_X3:  return 3;
-        case RegNumArm64::REGNUM_X4:  return 4;
-        case RegNumArm64::REGNUM_X5:  return 5;
-        case RegNumArm64::REGNUM_X6:  return 6;
-        case RegNumArm64::REGNUM_X7:  return 7;
-        case RegNumArm64::REGNUM_X8:  return 8;
-        case RegNumArm64::REGNUM_X9:  return 9;
-        case RegNumArm64::REGNUM_X10: return 10;
-        case RegNumArm64::REGNUM_X11: return 11;
-        case RegNumArm64::REGNUM_X12: return 12;
-        case RegNumArm64::REGNUM_X13: return 13;
-        case RegNumArm64::REGNUM_X14: return 14;
-        case RegNumArm64::REGNUM_X15: return 15;
-        case RegNumArm64::REGNUM_X16: return 16;
-        case RegNumArm64::REGNUM_X17: return 17;
-        case RegNumArm64::REGNUM_X18: return 18;
-        case RegNumArm64::REGNUM_X19: return 19;
-        case RegNumArm64::REGNUM_X20: return 20;
-        case RegNumArm64::REGNUM_X21: return 21;
-        case RegNumArm64::REGNUM_X22: return 22;
-        case RegNumArm64::REGNUM_X23: return 23;
-        case RegNumArm64::REGNUM_X24: return 24;
-        case RegNumArm64::REGNUM_X25: return 25;
-        case RegNumArm64::REGNUM_X26: return 26;
-        case RegNumArm64::REGNUM_X27: return 27;
-        case RegNumArm64::REGNUM_X28: return 28;
-        case RegNumArm64::REGNUM_FP:  return 29;
-        case RegNumArm64::REGNUM_LR:  return 30;
-        case RegNumArm64::REGNUM_SP:  return 31;
-        case RegNumArm64::REGNUM_PC:  return 32;
-        // fp registers
-        default:
-          return RegNum - static_cast<int>(RegNumArm64::REGNUM_COUNT) + 64;
-      }
-    case Triple::x86_64:
-      switch (static_cast<RegNumAmd64>(RegNum)) {
-        case RegNumAmd64::REGNUM_RAX: return 0;
-        case RegNumAmd64::REGNUM_RDX: return 1;
-        case RegNumAmd64::REGNUM_RCX: return 2;
-        case RegNumAmd64::REGNUM_RBX: return 3;
-        case RegNumAmd64::REGNUM_RSI: return 4;
-        case RegNumAmd64::REGNUM_RDI: return 5;
-        case RegNumAmd64::REGNUM_RBP: return 6;
-        case RegNumAmd64::REGNUM_RSP: return 7;
-        case RegNumAmd64::REGNUM_R8:  return 8;
-        case RegNumAmd64::REGNUM_R9:  return 9;
-        case RegNumAmd64::REGNUM_R10: return 10;
-        case RegNumAmd64::REGNUM_R11: return 11;
-        case RegNumAmd64::REGNUM_R12: return 12;
-        case RegNumAmd64::REGNUM_R13: return 13;
-        case RegNumAmd64::REGNUM_R14: return 14;
-        case RegNumAmd64::REGNUM_R15: return 15;
-        // fp registers
-        default:
-          return RegNum - static_cast<int>(RegNumAmd64::REGNUM_COUNT) + 17;
-      }
-    default:
-      assert(false && "Unexpected architecture");
-      return 0;
-  }
-}
-
-static int GetDwarfFpRegNum(Triple::ArchType ArchType)
-{
-  switch (ArchType) {
-    case Triple::x86:
-      return GetDwarfRegNum(ArchType, static_cast<int>(RegNumX86::REGNUM_FP));
-    case Triple::arm:   // fall through
-    case Triple::armeb: // fall through
-    case Triple::thumb: // fall through
-    case Triple::thumbeb:
-      return GetDwarfRegNum(ArchType, static_cast<int>(RegNumArm::REGNUM_FP));
-    case Triple::aarch64: // fall through
-    case Triple::aarch64_be:
-      return GetDwarfRegNum(ArchType, static_cast<int>(RegNumArm64::REGNUM_FP));
-    case Triple::x86_64:
-      return GetDwarfRegNum(ArchType, static_cast<int>(RegNumAmd64::REGNUM_FP));
-    default:
-      assert(false && "Unexpected architecture");
-      return 0;
-  }
-}
-
-static int GetRegOpSize(int DwarfRegNum) {
-  if (DwarfRegNum <= 31) {
-    return 1;
-  }
-  else if (DwarfRegNum < 128) {
-    return 2;
-  }
-  else if (DwarfRegNum < 16384) {
-    return 3;
-  }
-  else {
-    assert(false && "Too big register number");
-    return 0;
-  }
-}
-
-static void EmitBreg(MCObjectStreamer* Streamer, int DwarfRegNum, StringRef bytes) {
-  if (DwarfRegNum <= 31) {
-    Streamer->emitIntValue(DwarfRegNum + dwarf::DW_OP_breg0, 1);
-  }
-  else {
-    Streamer->emitIntValue(dwarf::DW_OP_bregx, 1);
-    Streamer->emitULEB128IntValue(DwarfRegNum);
-  }
-  Streamer->emitBytes(bytes);
-}
-
-static void EmitBreg(MCObjectStreamer* Streamer, int DwarfRegNum, int value) {
-  if (DwarfRegNum <= 31) {
-    Streamer->emitIntValue(DwarfRegNum + dwarf::DW_OP_breg0, 1);
-  }
-  else {
-    Streamer->emitIntValue(dwarf::DW_OP_bregx, 1);
-    Streamer->emitULEB128IntValue(DwarfRegNum);
-  }
-  Streamer->emitSLEB128IntValue(value);
-}
-
-static void EmitReg(MCObjectStreamer* Streamer, int DwarfRegNum) {
-  if (DwarfRegNum <= 31) {
-    Streamer->emitIntValue(DwarfRegNum + dwarf::DW_OP_reg0, 1);
-  }
-  else {
-    Streamer->emitIntValue(dwarf::DW_OP_regx, 1);
-    Streamer->emitULEB128IntValue(DwarfRegNum);
-  }
-}
-
-static void EmitVarLocation(MCObjectStreamer *Streamer,
-                     const ICorDebugInfo::NativeVarInfo &VarInfo,
-                     bool IsLocList = false) {
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-  Triple::ArchType ArchType = context.getObjectFileInfo()->getTargetTriple().getArch();
-
-  int DwarfRegNum;
-  int DwarfRegNum2;
-  int DwarfBaseRegNum;
-  unsigned Len;
-
-  bool IsByRef = false;
-  bool IsStk2 = false;
-  bool IsRegStk = false;
-
-  switch (VarInfo.loc.vlType) {
-    case ICorDebugInfo::VLT_REG_BYREF: // fall through
-      IsByRef = true;
-    case ICorDebugInfo::VLT_REG_FP:    // fall through
-    case ICorDebugInfo::VLT_REG: {
-      DwarfRegNum = GetDwarfRegNum(ArchType, VarInfo.loc.vlReg.vlrReg);
-      if (IsByRef) {
-        Len = 1 + GetRegOpSize(DwarfRegNum);
-        if (IsLocList) {
-          Streamer->emitIntValue(Len, 2);
-        } else {
-          Streamer->emitULEB128IntValue(Len);
-        }
-        EmitBreg(Streamer, DwarfRegNum, 0);
-      } else {
-        Len = GetRegOpSize(DwarfRegNum);
-        if (IsLocList) {
-          Streamer->emitIntValue(Len, 2);
-        } else {
-          Streamer->emitULEB128IntValue(Len);
-        }
-        EmitReg(Streamer, DwarfRegNum);
-      }
-
-      break;
-    }
-    case ICorDebugInfo::VLT_STK_BYREF: // fall through
-      IsByRef = true;
-    case ICorDebugInfo::VLT_STK2:
-      IsStk2 = true;
-    case ICorDebugInfo::VLT_FPSTK:
-    case ICorDebugInfo::VLT_STK: {
-      DwarfBaseRegNum = GetDwarfRegNum(ArchType, IsStk2 ? VarInfo.loc.vlStk2.vls2BaseReg :
-          VarInfo.loc.vlStk.vlsBaseReg);
-
-      SmallString<128> Tmp;
-      raw_svector_ostream OSE(Tmp);
-      encodeSLEB128(IsStk2 ? VarInfo.loc.vlStk2.vls2Offset :
-          VarInfo.loc.vlStk.vlsOffset, OSE);
-      StringRef OffsetRepr = OSE.str();
-
-      if (IsByRef) {
-        Len = OffsetRepr.size() + 1 + GetRegOpSize(DwarfBaseRegNum);
-        if (IsLocList) {
-          Streamer->emitIntValue(Len, 2);
-        } else {
-          Streamer->emitULEB128IntValue(Len);
-        }
-        EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr);
-        Streamer->emitIntValue(dwarf::DW_OP_deref, 1);
-      } else {
-        Len = OffsetRepr.size() + GetRegOpSize(DwarfBaseRegNum);
-        if (IsLocList) {
-          Streamer->emitIntValue(Len, 2);
-        } else {
-          Streamer->emitULEB128IntValue(Len);
-        }
-        EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr);
-      }
-
-      break;
-    }
-    case ICorDebugInfo::VLT_REG_REG: {
-      DwarfRegNum  = GetDwarfRegNum(ArchType, VarInfo.loc.vlRegReg.vlrrReg1);
-      DwarfRegNum2 = GetDwarfRegNum(ArchType, VarInfo.loc.vlRegReg.vlrrReg2);
-
-      Len = (GetRegOpSize(DwarfRegNum2) /* DW_OP_reg */ + 1 /* DW_OP_piece */ + 1 /* Reg size */)
-        + (GetRegOpSize(DwarfRegNum) /* DW_OP_reg */ + 1 /* DW_OP_piece */ + 1 /* Reg size */);
-      if (IsLocList) {
-        Streamer->emitIntValue(Len, 2);
-      } else {
-        Streamer->emitULEB128IntValue(Len + 1);
-      }
-
-      EmitReg(Streamer, DwarfRegNum2);
-      Streamer->emitIntValue(dwarf::DW_OP_piece, 1);
-      Streamer->emitULEB128IntValue(TargetPointerSize);
-
-      EmitReg(Streamer, DwarfRegNum);
-      Streamer->emitIntValue(dwarf::DW_OP_piece, 1);
-      Streamer->emitULEB128IntValue(TargetPointerSize);
-
-      break;
-    }
-    case ICorDebugInfo::VLT_REG_STK: // fall through
-      IsRegStk = true;
-    case ICorDebugInfo::VLT_STK_REG: {
-      DwarfRegNum = GetDwarfRegNum(ArchType, IsRegStk ? VarInfo.loc.vlRegStk.vlrsReg :
-          VarInfo.loc.vlStkReg.vlsrReg);
-      DwarfBaseRegNum = GetDwarfRegNum(ArchType, IsRegStk ? VarInfo.loc.vlRegStk.vlrsStk.vlrssBaseReg :
-          VarInfo.loc.vlStkReg.vlsrStk.vlsrsBaseReg);
-
-      SmallString<128> Tmp;
-      raw_svector_ostream OSE(Tmp);
-      encodeSLEB128(IsRegStk ? VarInfo.loc.vlRegStk.vlrsStk.vlrssOffset :
-          VarInfo.loc.vlStkReg.vlsrStk.vlsrsOffset, OSE);
-      StringRef OffsetRepr = OSE.str();
-
-      Len = (GetRegOpSize(DwarfRegNum) /* DW_OP_reg */ + 1 /* DW_OP_piece */ + 1 /* Reg size */) +
-          (GetRegOpSize(DwarfBaseRegNum) /*DW_OP_breg */ + OffsetRepr.size() + 1 /* DW_OP_piece */ + 1 /* Reg size */);
-
-      if (IsLocList) {
-        Streamer->emitIntValue(Len, 2);
-      } else {
-        Streamer->emitULEB128IntValue(Len + 1);
-      }
-
-      if (IsRegStk) {
-        EmitReg(Streamer, DwarfRegNum);
-        Streamer->emitIntValue(dwarf::DW_OP_piece, 1);
-        Streamer->emitULEB128IntValue(TargetPointerSize);
-
-        EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr);
-        Streamer->emitIntValue(dwarf::DW_OP_piece, 1);
-        Streamer->emitULEB128IntValue(TargetPointerSize);
-      } else {
-        EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr);
-        Streamer->emitIntValue(dwarf::DW_OP_piece, 1);
-        Streamer->emitULEB128IntValue(TargetPointerSize);
-
-        EmitReg(Streamer, DwarfRegNum);
-        Streamer->emitIntValue(dwarf::DW_OP_piece, 1);
-        Streamer->emitULEB128IntValue(TargetPointerSize);
-      }
-
-      break;
-    }
-    case ICorDebugInfo::VLT_FIXED_VA:
-      assert(false && "Unsupported varloc type!");
-    default:
-      assert(false && "Unknown varloc type!");
-      if (IsLocList) {
-        Streamer->emitIntValue(0, 2);
-      } else {
-        Streamer->emitULEB128IntValue(0);
-      }
-  }
-}
-
-// Lexical scope
-
-class LexicalScope
-{
-public:
-  LexicalScope(uint64_t Start, uint64_t End, bool IsFuncScope = false) :
-               Start(Start),
-               End(End),
-               IsFuncScope(IsFuncScope) {}
-
-  LexicalScope(VarInfo *Info) :
-               Start(Info->GetStartOffset()),
-               End(Info->GetEndOffset()),
-               IsFuncScope(false) { Vars.push_back(Info); }
-
-  bool IsContains(const VarInfo *Info) const {
-    return Start <= Info->GetStartOffset() && End >= Info->GetEndOffset();
-  }
-
-  void AddVar(VarInfo *Info);
-
-  void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection, const MCExpr *SymExpr);
-
-private:
-  uint64_t Start;
-  uint64_t End;
-  bool IsFuncScope;
-  std::vector<VarInfo*> Vars;
-  std::vector<LexicalScope> InnerScopes;
-};
-
-void LexicalScope::AddVar(VarInfo *Info) {
-  if (Info->IsParam() && IsFuncScope) {
-    Vars.push_back(Info);
-    return;
-  }
-
-  if (!IsContains(Info))
-    return;
-
-  uint64_t VarStart = Info->GetStartOffset();
-  uint64_t VarEnd = Info->GetEndOffset();
-
-  // Var belongs to inner scope
-  if (VarStart != Start || VarEnd != End) {
-    // Try to add variable to one the inner scopes
-    for (auto &Scope : InnerScopes) {
-      if (Scope.IsContains(Info)) {
-        Scope.AddVar(Info);
-        return;
-      }
-    }
-    // We need to create new inner scope for this var
-    InnerScopes.emplace_back(Info);
-  } else {
-    Vars.push_back(Info);
-  }
-}
-
-void LexicalScope::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection, const MCExpr *SymExpr) {
-  Streamer->SwitchSection(TypeSection);
-
-  if (!IsFuncScope)
-  {
-      // Dump lexical block DIE
-      MCContext &context = Streamer->getContext();
-      unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-      // Abbrev Number
-      Streamer->emitULEB128IntValue(DwarfAbbrev::LexicalBlock);
-
-      // DW_AT_low_pc
-      const MCExpr *StartExpr = MCConstantExpr::create(Start, context);
-      const MCExpr *LowPcExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr,
-          StartExpr, context);
-      Streamer->emitValue(LowPcExpr, TargetPointerSize);
-
-      // DW_AT_high_pc
-      Streamer->emitIntValue(End - Start, TargetPointerSize);
-  }
-
-  for (auto *Var : Vars) {
-    Var->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  for (auto &Scope : InnerScopes) {
-    Scope.Dump(TypeBuilder, Streamer, TypeSection, StrSection, SymExpr);
-  }
-
-  if (!IsFuncScope) {
-    // Terminate block
-    Streamer->emitIntValue(0, 1);
-  }
-}
-
-// StaticVarInfo
-
-class StaticVarInfo : public DwarfInfo
-{
-public:
-  StaticVarInfo(const DwarfStaticDataField *StaticField) : StaticField(StaticField) {}
-
-  void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override {};
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  const DwarfStaticDataField *StaticField;
-
-  void EmitLocation(MCObjectStreamer *Streamer);
-};
-
-void StaticVarInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  MCContext &context = Streamer->getContext();
-  MCSymbol *Sym = context.getOrCreateSymbol(Twine(StaticField->GetStaticDataName()));
-  if (Sym->isUndefined())
-    return;
-
-  DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-}
-
-void StaticVarInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::VariableStatic);
-
-  // DW_AT_specification
-  EmitInfoOffset(Streamer, StaticField, 4);
-
-  // DW_AT_location
-  EmitLocation(Streamer);
-}
-
-void StaticVarInfo::EmitLocation(MCObjectStreamer *Streamer) {
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-  MCSymbol *Sym = context.getOrCreateSymbol(Twine(StaticField->GetStaticDataName()));
-
-  SmallString<128> Tmp;
-  raw_svector_ostream OSE(Tmp);
-  encodeULEB128(StaticField->GetStaticOffset(), OSE);
-  StringRef OffsetRepr = OSE.str();
-
-  unsigned Len = 1 /* DW_OP_addr */ + TargetPointerSize;
-
-  // Need double deref
-  if (StaticField->IsStaticDataInObject()) {
-    Len += (1 /* DW_OP_deref */) * 2;
-  }
-
-  if (StaticField->GetStaticOffset() != 0) {
-    Len += 1 /* DW_OP_plus_uconst */ + OffsetRepr.size();
-  }
-
-  Streamer->emitULEB128IntValue(Len);
-  Streamer->emitIntValue(dwarf::DW_OP_addr, 1);
-  Streamer->emitSymbolValue(Sym, TargetPointerSize);
-
-  if (StaticField->IsStaticDataInObject()) {
-    Streamer->emitIntValue(dwarf::DW_OP_deref, 1);
-    Streamer->emitIntValue(dwarf::DW_OP_deref, 1);
-  }
-
-  if (StaticField->GetStaticOffset() != 0) {
-    Streamer->emitIntValue(dwarf::DW_OP_plus_uconst, 1);
-    Streamer->emitBytes(OffsetRepr);
-  }
-}
-
-// VarInfo
-
-VarInfo::VarInfo(const DebugVarInfo &Info, bool IsThis) :
-                 DebugInfo(Info),
-                 LocSymbol(nullptr),
-                 IsThis(IsThis) {
-  if (!Info.IsParam) {
-    assert(!Info.Ranges.empty());
-    StartOffset = Info.Ranges.front().startOffset;
-    EndOffset = Info.Ranges.back().endOffset;
-  } else {
-    // Params belong to func scope
-    StartOffset = 0xFFFFFFFF;
-    EndOffset = 0xFFFFFFFF;
-  }
-}
-
-void VarInfo::DumpLocsIfNeeded(MCObjectStreamer *Streamer,
-                               MCSection *LocSection,
-                               const MCExpr *SymExpr) {
-  if (!IsDebugLocNeeded())
-    return;
-
-  Streamer->SwitchSection(LocSection);
-
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-  LocSymbol = context.createTempSymbol();
-  Streamer->emitLabel(LocSymbol);
-
-  for (const auto &NativeInfo : DebugInfo.Ranges) {
-    const MCExpr *StartOffsetExpr = MCConstantExpr::create(NativeInfo.startOffset, context);
-    const MCExpr *EndOffsetExpr = MCConstantExpr::create(NativeInfo.endOffset, context);
-
-    // Begin address
-    const MCExpr *BeginAddrExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr,
-        StartOffsetExpr, context);
-    Streamer->emitValue(BeginAddrExpr, TargetPointerSize);
-
-    // End address
-    const MCExpr *EndAddrExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr,
-        EndOffsetExpr, context);
-    Streamer->emitValue(EndAddrExpr, TargetPointerSize);
-
-    // Expression
-    EmitVarLocation(Streamer, NativeInfo, true);
-  }
-
-  // Terminate list entry
-  Streamer->emitIntValue(0, TargetPointerSize);
-  Streamer->emitIntValue(0, TargetPointerSize);
-}
-
-void VarInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  if (IsThis) {
-    Streamer->emitBytes(StringRef("this"));
-  } else {
-    Streamer->emitBytes(StringRef(DebugInfo.Name));
-  }
-  Streamer->emitIntValue(0, 1);
-}
-
-void VarInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  bool IsDebugLocUsed = IsDebugLocNeeded();
-
-  // Abbrev Number
-  if (DebugInfo.IsParam) {
-    if (IsThis) {
-      Streamer->emitULEB128IntValue(IsDebugLocUsed ? DwarfAbbrev::FormalParameterThisLoc :
-          DwarfAbbrev::FormalParameterThis);
-    } else {
-      Streamer->emitULEB128IntValue(IsDebugLocUsed ? DwarfAbbrev::FormalParameterLoc :
-          DwarfAbbrev::FormalParameter);
-    }
-  } else {
-    Streamer->emitULEB128IntValue(IsDebugLocUsed ? DwarfAbbrev::VariableLoc :
-          DwarfAbbrev::Variable);
-  }
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_decl_file
-  Streamer->emitIntValue(1, 1);
-
-  // DW_AT_decl_line
-  Streamer->emitIntValue(1, 1);
-
-  // DW_AT_type
-  DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(DebugInfo.TypeIndex);
-  assert(Info != nullptr);
-
-  EmitInfoOffset(Streamer, Info, 4);
-
-  // DW_AT_location
-  if (IsDebugLocUsed) {
-    EmitSectionOffset(Streamer, LocSymbol, 4);
-  } else {
-    assert(DebugInfo.Ranges.size() == 1);
-    EmitVarLocation(Streamer, DebugInfo.Ranges[0]);
-  }
-}
-
-// SubprogramInfo
-
-SubprogramInfo::SubprogramInfo(const char *Name,
-                               int Size,
-                               DwarfMemberFunctionIdTypeInfo *MethodTypeInfo,
-                               const std::vector<DebugVarInfo> &DebugVarInfos,
-                               const std::vector<DebugEHClauseInfo> &DebugEHClauseInfos) :
-                               Name(Name),
-                               Size(Size),
-                               MethodTypeInfo(MethodTypeInfo),
-                               DebugEHClauseInfos(DebugEHClauseInfos) {
-  bool IsStatic = MethodTypeInfo->IsStatic();
-  for (unsigned i = 0; i < DebugVarInfos.size(); i++) {
-    VarInfos.emplace_back(DebugVarInfos[i], i == 0 && !IsStatic);
-  }
-}
-
-void SubprogramInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection, MCSection *LocSection) {
-  DumpDebugLoc(Streamer, LocSection);
-
-  DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  // Dump vars
-  DumpVars(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  // Dump try-catch blocks
-  Streamer->SwitchSection(TypeSection);
-  DumpEHClauses(Streamer, TypeSection);
-
-  // Terminate subprogram DIE
-  Streamer->emitIntValue(0, 1);
-}
-
-void SubprogramInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  MCContext &context = Streamer->getContext();
-  bool IsStatic = MethodTypeInfo->IsStatic();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-  Triple::ArchType ArchType = context.getObjectFileInfo()->getTargetTriple().getArch();
-
-  // Subprogram DIE
-
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(IsStatic ? DwarfAbbrev::SubprogramStatic :
-      DwarfAbbrev::Subprogram);
-
-  // DW_AT_specification
-  EmitInfoOffset(Streamer, MethodTypeInfo, 4);
-
-  // DW_AT_low_pc
-  MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name));
-  const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context);
-  Streamer->emitValue(SymExpr, TargetPointerSize);
-
-  // DW_AT_high_pc
-  Streamer->emitIntValue(Size, TargetPointerSize);
-
-  // DW_AT_frame_base
-  Streamer->emitULEB128IntValue(1);
-  Streamer->emitIntValue(GetDwarfFpRegNum(ArchType) + dwarf::DW_OP_reg0, 1);
-
-  if (!IsStatic) {
-    // DW_AT_object_pointer
-    uint32_t Offset = Streamer->getOrCreateDataFragment()->getContents().size();
-
-    Streamer->emitIntValue(Offset + 4, 4);
-  }
-}
-
-void SubprogramInfo::DumpDebugLoc(MCObjectStreamer *Streamer, MCSection *LocSection) {
-  MCContext &context = Streamer->getContext();
-  MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name));
-  const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context);
-
-  for (auto &VarInfo : VarInfos) {
-    VarInfo.DumpLocsIfNeeded(Streamer, LocSection, SymExpr);
-  }
-}
-
-void SubprogramInfo::DumpVars(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) {
-  MCContext &context = Streamer->getContext();
-  MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name));
-  const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context);
-
-  LexicalScope FuncScope(0, Size, true);
-
-  for (unsigned i = 0; i < VarInfos.size(); i++) {
-    FuncScope.AddVar(&VarInfos[i]);
-  }
-
-  FuncScope.Dump(TypeBuilder, Streamer, TypeSection, StrSection, SymExpr);
-}
-
-static void DumpEHClause(MCObjectStreamer *Streamer, MCSection *TypeSection, int Abbrev,
-                         const MCExpr *SymExpr, unsigned Offset, unsigned Length) {
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(Abbrev);
-
-  // DW_AT_low_pc
-  const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, context);
-  const MCExpr *AddrExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr,
-      OffsetExpr, context);
-
-  Streamer->emitValue(AddrExpr, TargetPointerSize);
-
-  // DW_AT_high_pc
-  Streamer->emitIntValue(Length, TargetPointerSize);
-}
-
-void SubprogramInfo::DumpEHClauses(MCObjectStreamer *Streamer, MCSection *TypeSection) {
-  MCContext &context = Streamer->getContext();
-
-  MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name));
-  const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context);
-
-  for (const auto &EHClause: DebugEHClauseInfos) {
-    // Try block DIE
-    DumpEHClause(Streamer, TypeSection, DwarfAbbrev::TryBlock,
-        SymExpr, EHClause.TryOffset, EHClause.TryLength);
-
-    // Catch block DIE
-    DumpEHClause(Streamer, TypeSection, DwarfAbbrev::CatchBlock,
-        SymExpr, EHClause.HandlerOffset, EHClause.HandlerLength);
-  }
-}
-
-// DwarfGen
-
-void DwarfGen::SetTypeBuilder(UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  assert(this->TypeBuilder == nullptr);
-  assert(TypeBuilder != nullptr);
-  this->TypeBuilder = TypeBuilder;
-  this->Streamer = TypeBuilder->GetStreamer();
-}
-
-void DwarfGen::EmitCompileUnit() {
-  MCContext &context = Streamer->getContext();
-
-  MCSymbol *LineSectionSymbol = nullptr;
-  MCSymbol *AbbrevSectionSymbol = nullptr;
-  if (context.getAsmInfo()->doesDwarfUseRelocationsAcrossSections()) {
-    LineSectionSymbol = Streamer->getDwarfLineTableSymbol(0);
-
-    Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
-    AbbrevSectionSymbol = context.createTempSymbol();
-    Streamer->emitLabel(AbbrevSectionSymbol);
-  }
-
-  MCSection *debugSection = context.getObjectFileInfo()->getDwarfInfoSection();
-  Streamer->SwitchSection(debugSection);
-
-  InfoStart = debugSection->getBeginSymbol();
-  InfoEnd = context.createTempSymbol();
-
-  // Length
-  const MCExpr *Length = MakeStartMinusEndExpr(*Streamer, *InfoStart, *InfoEnd, 4);
-  emitAbsValue(*Streamer, Length, 4);
-
-  // Version
-  Streamer->emitIntValue(context.getDwarfVersion(), 2);
-
-  // Unit type, Addr Size and Abbrev offset - DWARF >= 5
-  // Abbrev offset, Addr Size               - DWARF <= 4
-  unsigned addrSize = context.getAsmInfo()->getCodePointerSize();
-  if (context.getDwarfVersion() >= 5) {
-    Streamer->emitIntValue(dwarf::DW_UT_compile, 1);
-    Streamer->emitIntValue(addrSize, 1);
-  }
-
-  // Abbrev Offset
-  if (AbbrevSectionSymbol == nullptr) {
-    Streamer->emitIntValue(0, 4);
-  } else {
-    Streamer->emitSymbolValue(AbbrevSectionSymbol, 4,
-        context.getAsmInfo()->needsDwarfSectionOffsetDirective());
-  }
-
-  if (context.getDwarfVersion() <= 4)
-    Streamer->emitIntValue(addrSize, 1);
-
-  // CompileUnit DIE
-
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::CompileUnit);
-
-  // DW_AT_producer: CoreRT
-  Streamer->emitBytes(StringRef("CoreRT"));
-  Streamer->emitIntValue(0, 1);
-
-  // DW_AT_language
-#ifdef FEATURE_LANGID_CS
-  Streamer->EmitIntValue(DW_LANG_MICROSOFT_CSHARP, 2);
-#else
-  Streamer->emitIntValue(dwarf::DW_LANG_C_plus_plus, 2);
-#endif
-
-  // DW_AT_stmt_list
-  if (LineSectionSymbol == nullptr) {
-    Streamer->emitIntValue(0, 4);
-  } else {
-    Streamer->emitSymbolValue(LineSectionSymbol, 4,
-        context.getAsmInfo()->needsDwarfSectionOffsetDirective());
-  }
-}
-
-void DwarfGen::EmitSubprogramInfo(const char *FunctionName,
-                                  int FunctionSize,
-                                  unsigned MethodTypeIndex,
-                                  const std::vector<DebugVarInfo> &VarInfos,
-                                  const std::vector<DebugEHClauseInfo> &DebugEHClauseInfos) {
-  // return if CU isn't emitted
-  if (InfoStart == nullptr)
-    return;
-
-  if (MethodTypeIndex == 0)
-    return;
-
-  DwarfMemberFunctionIdTypeInfo *MethodTypeInfo = static_cast<DwarfMemberFunctionIdTypeInfo*>(
-      TypeBuilder->GetTypeInfoByIndex(MethodTypeIndex));
-  assert(MethodTypeInfo != nullptr);
-
-  MethodTypeInfo->SetLinkageName(FunctionName);
-
-  Subprograms.emplace_back(FunctionName, FunctionSize, MethodTypeInfo, VarInfos, DebugEHClauseInfos);
-}
-
-void DwarfGen::EmitAbbrev() {
-  // return if CU isn't emitted
-  if (InfoStart == nullptr)
-    return;
-
-  MCContext &context = Streamer->getContext();
-
-  DwarfAbbrev::Dump(Streamer, context.getDwarfVersion(),
-      context.getAsmInfo()->getCodePointerSize());
-}
-
-void DwarfGen::EmitAranges() {
-  // return if CU isn't emitted
-  if (InfoStart == nullptr)
-    return;
-
-  MCContext &context = Streamer->getContext();
-  Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
-
-  auto &Sections = context.getGenDwarfSectionSyms();
-
-  int Length = 4 + 2 + 4 + 1 + 1;
-  int AddrSize = context.getAsmInfo()->getCodePointerSize();
-  int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
-  if (Pad == 2 * AddrSize)
-    Pad = 0;
-  Length += Pad;
-
-  Length += 2 * AddrSize * Sections.size();
-  Length += 2 * AddrSize;
-
-  // Emit the header for this section.
-  // The 4 byte length not including the 4 byte value for the length.
-  Streamer->emitIntValue(Length - 4, 4);
-
-  // The 2 byte version, which is 2.
-  Streamer->emitIntValue(2, 2);
-
-  // The 4 byte offset to the compile unit in the .debug_info from the start
-  // of the .debug_info.
-  Streamer->emitSymbolValue(InfoStart, 4,
-                            context.getAsmInfo()->needsDwarfSectionOffsetDirective());
-
-  Streamer->emitIntValue(AddrSize, 1);
-
-  Streamer->emitIntValue(0, 1);
-
-  for(int i = 0; i < Pad; i++)
-    Streamer->emitIntValue(0, 1);
-
-  for (MCSection *Sec : Sections) {
-    const MCSymbol *StartSymbol = Sec->getBeginSymbol();
-    MCSymbol *EndSymbol = Sec->getEndSymbol(context);
-    assert(StartSymbol && "StartSymbol must not be NULL");
-    assert(EndSymbol && "EndSymbol must not be NULL");
-
-    const MCExpr *Addr = MCSymbolRefExpr::create(
-      StartSymbol, MCSymbolRefExpr::VK_None, context);
-    const MCExpr *Size = MakeStartMinusEndExpr(*Streamer,
-      *StartSymbol, *EndSymbol, 0);
-    Streamer->emitValue(Addr, AddrSize);
-    emitAbsValue(*Streamer, Size, AddrSize);
-  }
-
-  // Terminating zeros.
-  Streamer->emitIntValue(0, AddrSize);
-  Streamer->emitIntValue(0, AddrSize);
-}
-
-void DwarfGen::Finish() {
-  // return if CU isn't emitted
-  if (InfoStart == nullptr)
-    return;
-
-  MCContext &context = Streamer->getContext();
-
-  // Dump type info
-
-  MCSection *InfoSection = context.getObjectFileInfo()->getDwarfInfoSection();
-  MCSection *StrSection = context.getObjectFileInfo()->getDwarfStrSection();
-  MCSection *LocSection = context.getObjectFileInfo()->getDwarfLocSection();
-
-  TypeBuilder->EmitTypeInformation(InfoSection, StrSection);
-
-  // Dump subprograms
-
-  for (auto &Subprogram : Subprograms) {
-    Subprogram.Dump(TypeBuilder, Streamer, InfoSection, StrSection, LocSection);
-  }
-
-  // Dump static vars
-
-  for (const auto *ClassTypeInfo : TypeBuilder->GetClassesWithStaticFields()) {
-    for (const auto &StaticField : ClassTypeInfo->GetStaticFields()) {
-      StaticVarInfo Info(&StaticField);
-      Info.Dump(TypeBuilder, Streamer, InfoSection, StrSection);
-    }
-  }
-
-  // Add the NULL terminating the Compile Unit DIE's.
-  Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
-
-  Streamer->emitIntValue(0, 1);
-
-  Streamer->emitLabel(InfoEnd);
-
-  Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
-
-  // Terminate the abbreviations for this compilation unit
-  Streamer->emitIntValue(0, 1);
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfGen.h b/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfGen.h
deleted file mode 100644 (file)
index 40f3d28..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-//===---- dwarfGen.h --------------------------------------------*- C++ -*-===//
-//
-// dwarf generator is used to generate dwarf debuginfo.
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#pragma once
-
-#include "llvm/MC/MCObjectStreamer.h"
-
-#include "dwarfTypeBuilder.h"
-#include "jitDebugInfo.h"
-
-#include <vector>
-
-class VarInfo : public DwarfInfo
-{
-public:
-  VarInfo(const DebugVarInfo &Info, bool IsThis);
-
-  bool IsDebugLocNeeded() const { return DebugInfo.Ranges.size() > 1; }
-
-  void DumpLocsIfNeeded(MCObjectStreamer *Streamer, MCSection *LocSection, const MCExpr *SymExpr);
-
-  uint64_t GetStartOffset() const { return StartOffset; }
-
-  uint64_t GetEndOffset() const { return EndOffset; }
-
-  bool IsParam() const { return DebugInfo.IsParam; }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  DebugVarInfo DebugInfo;
-  MCSymbol *LocSymbol;
-  bool IsThis;
-  uint64_t StartOffset;
-  uint64_t EndOffset;
-};
-
-class SubprogramInfo : public DwarfInfo
-{
-public:
-  using DwarfInfo::Dump;
-
-  SubprogramInfo(const char *Name,
-                 int Size,
-                 DwarfMemberFunctionIdTypeInfo *MethodTypeInfo,
-                 const std::vector<DebugVarInfo> &DebugVarInfos,
-                 const std::vector<DebugEHClauseInfo> &DebugEHClauseInfos);
-
-  void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection, MCSection *LocSection);
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override {}
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  void DumpDebugLoc(MCObjectStreamer *Streamer, MCSection *LocSection);
-  void DumpVars(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection);
-  void DumpEHClauses(MCObjectStreamer *Streamer, MCSection *TypeSection);
-
-  std::string Name;
-  int Size;
-  DwarfMemberFunctionIdTypeInfo *MethodTypeInfo;
-  std::vector<DebugEHClauseInfo> DebugEHClauseInfos;
-  std::vector<VarInfo> VarInfos;
-};
-
-class DwarfGen
-{
-public:
-  DwarfGen() : Streamer(nullptr),
-               TypeBuilder(nullptr),
-               InfoStart(nullptr),
-               InfoEnd(nullptr) {}
-
-  void SetTypeBuilder(UserDefinedDwarfTypesBuilder *TypeBuilder);
-  void EmitCompileUnit();
-  void EmitSubprogramInfo(const char *FunctionName,
-                          int FunctionSize,
-                          unsigned MethodTypeIndex,
-                          const std::vector<DebugVarInfo> &VarsInfo,
-                          const std::vector<DebugEHClauseInfo> &DebugEHClauseInfos);
-
-  void EmitAbbrev();
-  void EmitAranges();
-  void Finish();
-
-private:
-  MCObjectStreamer *Streamer;
-  UserDefinedDwarfTypesBuilder *TypeBuilder;
-
-  MCSymbol *InfoStart;
-  MCSymbol *InfoEnd;
-
-  std::vector<SubprogramInfo> Subprograms;
-};
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfTypeBuilder.cpp b/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfTypeBuilder.cpp
deleted file mode 100644 (file)
index 6d663e0..0000000
+++ /dev/null
@@ -1,823 +0,0 @@
-//===---- dwarfTypeBuilder.cpp ----------------------------------*- C++ -*-===//
-//
-// dwarf type builder implementation
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#include "dwarfTypeBuilder.h"
-#include "dwarfAbbrev.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCObjectFileInfo.h"
-
-#include <sstream>
-#include <vector>
-
-// DwarfInfo
-
-void DwarfInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumped)
-    return;
-
-  IsDumped = true;
-
-  MCContext &context = Streamer->getContext();
-
-  InfoSymbol = context.createTempSymbol();
-  InfoExpr = CreateOffsetExpr(context, TypeSection->getBeginSymbol(), InfoSymbol);
-
-  DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  Streamer->SwitchSection(StrSection);
-  StrSymbol = context.createTempSymbol();
-  Streamer->emitLabel(StrSymbol);
-  DumpStrings(Streamer);
-
-  Streamer->SwitchSection(TypeSection);
-  Streamer->emitLabel(InfoSymbol);
-  DumpTypeInfo(Streamer, TypeBuilder);
-}
-
-void DwarfInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  IsDumpedTypes = true;
-}
-
-void DwarfInfo::EmitSectionOffset(MCObjectStreamer *Streamer,
-                                  MCSymbol *Symbol,
-                                  unsigned Size,
-                                  uint32_t Offset) {
-  MCContext &context = Streamer->getContext();
-
-  if (context.getAsmInfo()->doesDwarfUseRelocationsAcrossSections()) {
-    if (Offset == 0) {
-      Streamer->emitSymbolValue(Symbol, Size);
-    } else {
-      const MCSymbolRefExpr *SymbolExpr = MCSymbolRefExpr::create(Symbol,
-          MCSymbolRefExpr::VK_None, context);
-      const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, context);
-      const MCExpr *Expr = MCBinaryExpr::createAdd(SymbolExpr, OffsetExpr, context);
-      Streamer->emitValue(Expr, Size);
-    }
-  } else {
-    Streamer->emitIntValue(Symbol->getOffset() + Offset, Size);
-  }
-}
-
-const MCExpr *DwarfInfo::CreateOffsetExpr(MCContext &Context,
-                                          MCSymbol *BeginSymbol,
-                                          MCSymbol *Symbol) {
-  MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
-  const MCExpr *StartExpr =
-    MCSymbolRefExpr::create(BeginSymbol, Variant, Context);
-  const MCExpr *EndExpr =
-    MCSymbolRefExpr::create(Symbol, Variant, Context);
-  return MCBinaryExpr::createSub(EndExpr, StartExpr, Context);
-}
-
-void DwarfInfo::EmitOffset(MCObjectStreamer *Streamer,
-                           const MCExpr *OffsetExpr,
-                           unsigned Size) {
-  MCContext &context = Streamer->getContext();
-
-  if (!context.getAsmInfo()->hasAggressiveSymbolFolding()) {
-    MCSymbol *Temp = context.createTempSymbol();
-    Streamer->emitAssignment(Temp, OffsetExpr);
-    OffsetExpr = MCSymbolRefExpr::create(Temp, context);
-  }
-
-  Streamer->emitValue(OffsetExpr, Size);
-}
-
-void DwarfInfo::EmitInfoOffset(MCObjectStreamer *Streamer, const DwarfInfo *Info, unsigned Size) {
-  uint64_t Offset = Info->InfoSymbol->getOffset();
-  if (Offset != 0) {
-    Streamer->emitIntValue(Offset, Size);
-  } else {
-    EmitOffset(Streamer, Info->InfoExpr, Size);
-  }
-}
-
-// DwarfPrimitiveTypeInfo
-
-struct PrimitiveTypeDesc {
-  const char *Name;
-  int Encoding;
-  unsigned ByteSize;
-};
-
-static PrimitiveTypeDesc GetPrimitiveTypeDesc(PrimitiveTypeFlags Type, unsigned TargetPointerSize) {
-  switch (Type) {
-    case PrimitiveTypeFlags::Boolean: return {"bool",           dwarf::DW_ATE_boolean,  1};
-    case PrimitiveTypeFlags::Char:    return {"char16_t",       dwarf::DW_ATE_UTF,      2};
-    case PrimitiveTypeFlags::SByte:   return {"sbyte",          dwarf::DW_ATE_signed,   1};
-    case PrimitiveTypeFlags::Byte:    return {"byte",           dwarf::DW_ATE_unsigned, 1};
-    case PrimitiveTypeFlags::Int16:   return {"short",          dwarf::DW_ATE_signed,   2};
-    case PrimitiveTypeFlags::UInt16:  return {"ushort",         dwarf::DW_ATE_unsigned, 2};
-    case PrimitiveTypeFlags::Int32:   return {"int",            dwarf::DW_ATE_signed,   4};
-    case PrimitiveTypeFlags::UInt32:  return {"uint",           dwarf::DW_ATE_unsigned, 4};
-    case PrimitiveTypeFlags::Int64:   return {"long",           dwarf::DW_ATE_signed,   8};
-    case PrimitiveTypeFlags::UInt64:  return {"ulong",          dwarf::DW_ATE_unsigned, 8};
-    case PrimitiveTypeFlags::IntPtr:  return {"System.IntPtr",  dwarf::DW_ATE_signed,   TargetPointerSize};
-    case PrimitiveTypeFlags::UIntPtr: return {"System.UIntPtr", dwarf::DW_ATE_unsigned, TargetPointerSize};
-    case PrimitiveTypeFlags::Single:  return {"float",          dwarf::DW_ATE_float,    4};
-    case PrimitiveTypeFlags::Double:  return {"double",         dwarf::DW_ATE_float,    8};
-    default:
-      assert(false && "Unexpected type");
-      return {nullptr, 0, 0};
-  }
-}
-
-void DwarfPrimitiveTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-  PrimitiveTypeDesc TD = GetPrimitiveTypeDesc(Type, TargetPointerSize);
-  if (TD.Name == nullptr)
-    return;
-
-  Streamer->emitBytes(StringRef(TD.Name));
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfPrimitiveTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-  PrimitiveTypeDesc TD = GetPrimitiveTypeDesc(Type, TargetPointerSize);
-  if (TD.Name == nullptr)
-    return;
-
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::BaseType);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_encoding
-  Streamer->emitIntValue(TD.Encoding, 1);
-
-  // DW_AT_byte_size
-  Streamer->emitIntValue(TD.ByteSize, 1);
-}
-
-// DwarfVoidTypeInfo
-
-void DwarfVoidTypeInfo::DumpStrings(MCObjectStreamer* Streamer) {
-  Streamer->emitBytes(StringRef("void"));
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfVoidTypeInfo::DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::VoidType);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-}
-
-// DwarfEnumerator
-
-void DwarfEnumerator::DumpStrings(MCObjectStreamer *Streamer) {
-  Streamer->emitBytes(Name);
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfEnumerator::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  uint8_t Size = EnumTypeInfo->GetByteSize();
-
-  // Abbrev Number
-  switch (Size) {
-    case 1:
-      Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator1);
-      break;
-    case 2:
-      Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator2);
-      break;
-    case 4:
-      Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator4);
-      break;
-    case 8:
-      Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator8);
-      break;
-    default:
-      assert(false && "Unexpected byte size value");
-  }
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_const_value
-  Streamer->emitIntValue(Value, Size);
-}
-
-// DwarfEnumTypeInfo
-
-DwarfEnumTypeInfo::DwarfEnumTypeInfo(const EnumTypeDescriptor &TypeDescriptor,
-                                     const EnumRecordTypeDescriptor *TypeRecords) :
-                                     Name(TypeDescriptor.Name),
-                                     ElementType(TypeDescriptor.ElementType) {
-  for (uint64 i = 0; i < TypeDescriptor.ElementCount; i++) {
-    Records.emplace_back(TypeRecords[i], this);
-  }
-}
-
-void DwarfEnumTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(ElementType);
-  assert(Info != nullptr);
-
-  Info->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-}
-
-void DwarfEnumTypeInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumped)
-    return;
-
-  MCContext &context = Streamer->getContext();
-  unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize();
-
-  DwarfPrimitiveTypeInfo *ElementTypeInfo = static_cast<DwarfPrimitiveTypeInfo*>(
-      TypeBuilder->GetTypeInfoByIndex(ElementType));
-  assert(ElementTypeInfo != nullptr);
-
-  PrimitiveTypeDesc TD = GetPrimitiveTypeDesc(ElementTypeInfo->GetType(), TargetPointerSize);
-  ByteSize = TD.ByteSize;
-
-  DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  for (auto &Enumerator : Records) {
-    Enumerator.Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  // Terminate DIE
-  Streamer->SwitchSection(TypeSection);
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfEnumTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  Streamer->emitBytes(Name);
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfEnumTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::EnumerationType);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_type
-  DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(ElementType);
-  assert(Info != nullptr);
-
-  EmitInfoOffset(Streamer, Info, 4);
-
-  // DW_AT_byte_size
-  Streamer->emitIntValue(ByteSize, 1);
-}
-
-// DwarfDataField
-
-void DwarfDataField::DumpStrings(MCObjectStreamer *Streamer) {
-  Streamer->emitBytes(StringRef(Name));
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfDataField::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  DwarfInfo *MemberTypeInfo = TypeBuilder->GetTypeInfoByIndex(TypeIndex);
-  assert(MemberTypeInfo != nullptr);
-
-  MemberTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-}
-
-void DwarfDataField::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::ClassMember);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_type
-  DwarfInfo *MemberTypeInfo = TypeBuilder->GetTypeInfoByIndex(TypeIndex);
-  assert(MemberTypeInfo != nullptr);
-  EmitInfoOffset(Streamer, MemberTypeInfo, 4);
-
-  // DW_AT_data_member_location
-  Streamer->emitIntValue(Offset, 4);
-}
-
-// DwarfStaticDataField
-
-void DwarfStaticDataField::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::ClassMemberStatic);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_type
-  DwarfInfo *MemberTypeInfo = TypeBuilder->GetTypeInfoByIndex(TypeIndex);
-  assert(MemberTypeInfo != nullptr);
-  EmitInfoOffset(Streamer, MemberTypeInfo, 4);
-}
-
-// DwarfClassTypeInfo
-
-DwarfClassTypeInfo::DwarfClassTypeInfo(const ClassTypeDescriptor &ClassDescriptor,
-                                       const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-                                       const DataFieldDescriptor *FieldsDescriptors,
-                                       const StaticDataFieldDescriptor *StaticsDescriptors) :
-                                       Name(ClassDescriptor.Name),
-                                       IsStruct(ClassDescriptor.IsStruct),
-                                       BaseClassId(ClassDescriptor.BaseClassId),
-                                       Size(ClassDescriptor.InstanceSize),
-                                       IsForwardDecl(false) {
-  int32_t staticIdx = 0;
-  for (int32_t i = 0; i < ClassFieldsDescriptor.FieldsCount; i++) {
-    if (FieldsDescriptors[i].Offset == 0xFFFFFFFF) {
-      StaticFields.emplace_back(FieldsDescriptors[i], StaticsDescriptors[staticIdx++]);
-    } else {
-      Fields.emplace_back(FieldsDescriptors[i]);
-    }
-  }
-}
-
-void DwarfClassTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  if (BaseClassId != 0) {
-    DwarfInfo *BaseClassInfo = TypeBuilder->GetTypeInfoByIndex(BaseClassId);
-    assert(BaseClassInfo != nullptr);
-
-    BaseClassInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  for (auto &Field : Fields) {
-    Field.DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  for (auto &StaticField : StaticFields) {
-    StaticField.DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  for (auto *Function : MemberFunctions) {
-    Function->DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-}
-
-void DwarfClassTypeInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumped)
-    return;
-
-  DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  if (IsForwardDecl)
-    return;
-
-  for (auto &Field : Fields) {
-    Field.Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  for (auto &StaticField : StaticFields) {
-    StaticField.Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  for (auto *Function : MemberFunctions) {
-    Function->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  // Terminate DIE
-  Streamer->SwitchSection(TypeSection);
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfClassTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  Streamer->emitBytes(StringRef(Name));
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfClassTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(IsForwardDecl ? DwarfAbbrev::ClassTypeDecl : DwarfAbbrev::ClassType);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  if (!IsForwardDecl) {
-    // DW_AT_byte_size
-    Streamer->emitIntValue(Size, 4);
-  }
-
-  if (BaseClassId != 0) {
-    DwarfInfo *BaseClassInfo = TypeBuilder->GetTypeInfoByIndex(BaseClassId);
-    assert(BaseClassInfo != nullptr);
-
-    // DW_TAG_inheritance DIE
-
-    // Abbrev Number
-    Streamer->emitULEB128IntValue(DwarfAbbrev::ClassInheritance);
-
-    // DW_AT_type
-    EmitInfoOffset(Streamer, BaseClassInfo, 4);
-
-    // DW_AT_data_member_location = 0
-    Streamer->emitIntValue(0, 1);
-  }
-}
-
-// DwarfSimpleArrayTypeInfo
-
-void DwarfSimpleArrayTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  DwarfInfo *ElementInfo = TypeBuilder->GetTypeInfoByIndex(ElementType);
-  assert(ElementInfo != nullptr);
-
-  ElementInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-}
-
-void DwarfSimpleArrayTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  // nothing to dump
-}
-
-void DwarfSimpleArrayTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::ArrayType);
-
-  DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(ElementType);
-  assert(Info != nullptr);
-
-  // DW_AT_type
-  EmitInfoOffset(Streamer, Info, 4);
-
-  // DW_TAG_subrange_type DIE
-
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::SubrangeType);
-
-  // DW_AT_upper_bound
-  Streamer->emitULEB128IntValue(Size - 1);
-
-  // Terminate DIE
-  Streamer->emitIntValue(0, 1);
-}
-
-// DwarfPointerTypeInfo
-
-void DwarfPointerTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-    MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(TypeDesc.ElementType);
-  assert(Info != nullptr);
-
-  Info->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-}
-
-void DwarfPointerTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  // nothing to dump
-}
-
-void DwarfPointerTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(TypeDesc.IsReference ? DwarfAbbrev::ReferenceType : DwarfAbbrev::PointerType);
-
-  DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(TypeDesc.ElementType);
-  assert(Info != nullptr);
-
-  // DW_AT_type
-  EmitInfoOffset(Streamer, Info, 4);
-
-  // DW_AT_byte_size
-  Streamer->emitIntValue(TypeDesc.Is64Bit ? 8 : 4, 1);
-}
-
-// DwarfVoidPtrTypeInfo
-
-void DwarfVoidPtrTypeInfo::DumpStrings(MCObjectStreamer* Streamer) {
-  // nothing to dump
-}
-
-void DwarfVoidPtrTypeInfo::DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) {
-  // Abbrev Number
-  Streamer->emitULEB128IntValue(DwarfAbbrev::VoidPointerType);
-}
-
-// DwarfMemberFunctionTypeInfo
-
-DwarfMemberFunctionTypeInfo::DwarfMemberFunctionTypeInfo(
-    const MemberFunctionTypeDescriptor& MemberDescriptor,
-    uint32_t const *const ArgumentTypes,
-    bool IsStaticMethod) :
-    TypeDesc(MemberDescriptor),
-    IsStaticMethod(IsStaticMethod) {
-  for (uint16_t i = 0; i < MemberDescriptor.NumberOfArguments; i++) {
-    this->ArgumentTypes.push_back(ArgumentTypes[i]);
-  }
-}
-
-void DwarfMemberFunctionTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  // nothing to dump
-}
-
-void DwarfMemberFunctionTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // nothing to dump
-}
-
-// DwarfMemberFunctionIdTypeInfo
-
-void DwarfMemberFunctionIdTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) {
-  if (IsDumpedTypes)
-    return;
-
-  DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  // Dump return type
-  DwarfInfo *ReturnTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetReturnTypeIndex());
-  assert(ReturnTypeInfo != nullptr);
-
-  ReturnTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-
-  // Dump this pointer type
-  if (!MemberFunctionTypeInfo->IsStatic()) {
-    DwarfInfo *ThisPtrTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetThisPtrTypeIndex());
-    assert(ThisPtrTypeInfo != nullptr);
-
-    ThisPtrTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-
-  // Dump argument types
-  for (uint32_t ArgTypeIndex : MemberFunctionTypeInfo->GetArgTypes()) {
-    DwarfInfo *ArgTypeInfo = TypeBuilder->GetTypeInfoByIndex(ArgTypeIndex);
-    assert(ArgTypeInfo != nullptr);
-    ArgTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection);
-  }
-}
-
-void DwarfMemberFunctionIdTypeInfo::DumpStrings(MCObjectStreamer *Streamer) {
-  Streamer->emitBytes(StringRef(Name));
-  Streamer->emitIntValue(0, 1);
-
-  MCContext &context = Streamer->getContext();
-  LinkageNameSymbol = context.createTempSymbol();
-  Streamer->emitLabel(LinkageNameSymbol);
-  Streamer->emitBytes(StringRef(LinkageName));
-  Streamer->emitIntValue(0, 1);
-}
-
-void DwarfMemberFunctionIdTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) {
-  // Abbrev Number
-  bool IsStatic = MemberFunctionTypeInfo->IsStatic();
-
-  Streamer->emitULEB128IntValue(IsStatic ? DwarfAbbrev::SubprogramStaticSpec : DwarfAbbrev::SubprogramSpec);
-
-  // DW_AT_name
-  EmitSectionOffset(Streamer, StrSymbol, 4);
-
-  // DW_AT_linkage_name
-  EmitSectionOffset(Streamer, LinkageNameSymbol, 4);
-
-  // DW_AT_decl_file
-  Streamer->emitIntValue(1, 1);
-
-  // DW_AT_decl_line
-  Streamer->emitIntValue(1, 1);
-
-  // DW_AT_type
-  DwarfInfo *ReturnTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetReturnTypeIndex());
-  assert(ReturnTypeInfo != nullptr);
-
-  EmitInfoOffset(Streamer, ReturnTypeInfo, 4);
-
-  if (!IsStatic) {
-    // DW_AT_object_pointer
-    uint32_t Offset = Streamer->getOrCreateDataFragment()->getContents().size();
-
-    Streamer->emitIntValue(Offset + 4, 4);
-
-    // This formal parameter DIE
-    DwarfInfo *ThisTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetThisPtrTypeIndex());
-    assert(ThisTypeInfo != nullptr);
-
-    // Abbrev Number
-    Streamer->emitULEB128IntValue(DwarfAbbrev::FormalParameterThisSpec);
-
-    // DW_AT_type
-    EmitInfoOffset(Streamer, ThisTypeInfo, 4);
-  }
-
-  for (uint32_t ArgTypeIndex : MemberFunctionTypeInfo->GetArgTypes()) {
-    DwarfInfo *ArgTypeInfo = TypeBuilder->GetTypeInfoByIndex(ArgTypeIndex);
-    assert(ArgTypeInfo != nullptr);
-
-    // Formal parameter DIE
-
-    // Abbrev Number
-    Streamer->emitULEB128IntValue(DwarfAbbrev::FormalParameterSpec);
-
-    // DW_AT_type
-    EmitInfoOffset(Streamer, ArgTypeInfo, 4);
-  }
-
-  // Ternimate DIE
-  Streamer->emitIntValue(0, 1);
-}
-
-// DwarfTypesBuilder
-
-void UserDefinedDwarfTypesBuilder::EmitTypeInformation(
-    MCSection *TypeSection,
-    MCSection *StrSection) {
-  for (auto &Info : DwarfTypes) {
-    Info->Dump(this, Streamer, TypeSection, StrSection);
-  }
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetEnumTypeIndex(
-    const EnumTypeDescriptor &TypeDescriptor,
-    const EnumRecordTypeDescriptor *TypeRecords) {
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-  UserDefinedTypes.push_back(std::make_pair(TypeDescriptor.Name, TypeIndex));
-  DwarfTypes.push_back(std::make_unique<DwarfEnumTypeInfo>(TypeDescriptor, TypeRecords));
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetClassTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor) {
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-  DwarfTypes.push_back(std::make_unique<DwarfClassTypeInfo>(ClassDescriptor));
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetCompleteClassTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor,
-    const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-    const DataFieldDescriptor *FieldsDescriptors,
-    const StaticDataFieldDescriptor *StaticsDescriptors) {
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-  UserDefinedTypes.push_back(std::make_pair(ClassDescriptor.Name, TypeIndex));
-
-  DwarfClassTypeInfo *ClassTypeInfo = new DwarfClassTypeInfo(ClassDescriptor, ClassFieldsDescriptor,
-      FieldsDescriptors, StaticsDescriptors);
-
-  DwarfTypes.push_back(std::unique_ptr<DwarfClassTypeInfo>(ClassTypeInfo));
-
-  if (ClassTypeInfo->GetStaticFields().size() > 0) {
-    ClassesWithStaticFields.push_back(ClassTypeInfo);
-  }
-
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetArrayTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor,
-    const ArrayTypeDescriptor &ArrayDescriptor) {
-  // Create corresponding class info
-  ClassTypeDescriptor ArrayClassDescriptor = ClassDescriptor;
-
-  std::vector<DataFieldDescriptor> FieldDescs;
-  unsigned FieldOffset = TargetPointerSize;
-
-  FieldDescs.push_back({GetPrimitiveTypeIndex(PrimitiveTypeFlags::Int32), FieldOffset, "m_NumComponents"});
-  FieldOffset += TargetPointerSize;
-
-  if (ArrayDescriptor.IsMultiDimensional == 1) {
-    unsigned BoundsTypeIndex = GetSimpleArrayTypeIndex(GetPrimitiveTypeIndex(PrimitiveTypeFlags::Int32), ArrayDescriptor.Rank);
-    FieldDescs.push_back({BoundsTypeIndex, FieldOffset, "m_Bounds"});
-    FieldOffset += 2 * 4 * ArrayDescriptor.Rank;
-  }
-
-  unsigned DataTypeIndex = GetSimpleArrayTypeIndex(ArrayDescriptor.ElementType, 0);
-  FieldDescs.push_back({DataTypeIndex, FieldOffset, "m_Data"});
-
-  ClassFieldsTypeDescriptior FieldsTypeDesc =
-      {TargetPointerSize, ArrayDescriptor.IsMultiDimensional ? 3 : 2};
-
-  ArrayClassDescriptor.InstanceSize = FieldOffset;
-
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-  UserDefinedTypes.push_back(std::make_pair(ArrayClassDescriptor.Name, TypeIndex));
-  DwarfTypes.push_back(std::make_unique<DwarfClassTypeInfo>(ArrayClassDescriptor, FieldsTypeDesc, FieldDescs.data(), nullptr));
-
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor)
-{
-  unsigned VoidTypeIndex = GetPrimitiveTypeIndex(PrimitiveTypeFlags::Void);
-
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-
-  // Creating a pointer to what DWARF considers Void type (DW_TAG_unspecified_type -
-  // per http://eagercon.com/dwarf/issues/minutes-001017.htm) leads to unhappines
-  // since debuggers don't really know how to handle that. The Clang symbol parser
-  // in LLDB only handles DW_TAG_unspecified_type if it's named
-  // "nullptr_t" or "decltype(nullptr)".
-  //
-  // We resort to this kludge to generate the exact same debug info for void* that
-  // clang would generate (pointer type with no element type specified).
-  if (PointerDescriptor.ElementType == VoidTypeIndex)
-    DwarfTypes.push_back(std::make_unique<DwarfVoidPtrTypeInfo>());
-  else
-    DwarfTypes.push_back(std::make_unique<DwarfPointerTypeInfo>(PointerDescriptor));
-
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-    uint32_t const *const ArgumentTypes)
-{
-  bool IsStatic = MemberDescriptor.TypeIndexOfThisPointer == GetPrimitiveTypeIndex(PrimitiveTypeFlags::Void);
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-  DwarfTypes.push_back(std::make_unique<DwarfMemberFunctionTypeInfo>(MemberDescriptor, ArgumentTypes, IsStatic));
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor)
-{
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-
-  DwarfMemberFunctionTypeInfo *MemberFunctionTypeInfo = static_cast<DwarfMemberFunctionTypeInfo*>(
-      GetTypeInfoByIndex(MemberIdDescriptor.MemberFunction));
-  assert(MemberFunctionTypeInfo != nullptr);
-
-  DwarfMemberFunctionIdTypeInfo *MemberFunctionIdTypeInfo =
-      new DwarfMemberFunctionIdTypeInfo(MemberIdDescriptor, MemberFunctionTypeInfo);
-
-  DwarfTypes.push_back(std::unique_ptr<DwarfMemberFunctionIdTypeInfo>(MemberFunctionIdTypeInfo));
-
-  DwarfClassTypeInfo *ParentClassInfo = static_cast<DwarfClassTypeInfo*>(
-      GetTypeInfoByIndex(MemberIdDescriptor.ParentClass));
-  assert(ParentClassInfo != nullptr);
-
-  ParentClassInfo->AddMemberFunction(MemberFunctionIdTypeInfo);
-
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) {
-  auto Iter = PrimitiveDwarfTypes.find(Type);
-  if (Iter != PrimitiveDwarfTypes.end())
-    return Iter->second;
-
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-
-  if (Type == PrimitiveTypeFlags::Void)
-    DwarfTypes.push_back(std::make_unique<DwarfVoidTypeInfo>());
-  else 
-    DwarfTypes.push_back(std::make_unique<DwarfPrimitiveTypeInfo>(Type));
-
-  PrimitiveDwarfTypes.insert(std::make_pair(Type, TypeIndex));
-
-  return TypeIndex;
-}
-
-unsigned UserDefinedDwarfTypesBuilder::GetSimpleArrayTypeIndex(unsigned ElemIndex, unsigned Size) {
-  auto Iter = SimpleArrayDwarfTypes.find(ElemIndex);
-  if (Iter != SimpleArrayDwarfTypes.end()) {
-    auto CountMap = Iter->second;
-    auto CountIter = CountMap.find(Size);
-    if (CountIter != CountMap.end())
-      return CountIter->second;
-  }
-
-  unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size());
-  DwarfTypes.push_back(std::make_unique<DwarfSimpleArrayTypeInfo>(ElemIndex, Size));
-
-  SimpleArrayDwarfTypes[ElemIndex][Size] = TypeIndex;
-
-  return TypeIndex;
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfTypeBuilder.h b/src/coreclr/tools/aot/ObjWriter/debugInfo/dwarf/dwarfTypeBuilder.h
deleted file mode 100644 (file)
index 8294245..0000000
+++ /dev/null
@@ -1,385 +0,0 @@
-//===---- dwarfTypeBuilder.h ------------------------------------*- C++ -*-===//
-//
-// type builder is used to convert .Net types into Dwarf debuginfo.
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#pragma once
-
-#include "debugInfo/typeBuilder.h"
-
-#include <vector>
-#include <unordered_map>
-
-class UserDefinedDwarfTypesBuilder;
-
-class DwarfInfo
-{
-public:
-  DwarfInfo() :
-      StrSymbol(nullptr),
-      InfoSymbol(nullptr),
-      IsDumped(false),
-      IsDumpedTypes(false) {}
-
-  virtual ~DwarfInfo() {}
-
-  virtual void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection);
-
-  virtual void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection);
-
-  MCSymbol *GetInfoSymbol() { return InfoSymbol; }
-
-  const MCExpr *GetInfoExpr() { return InfoExpr; }
-
-protected:
-  virtual void DumpStrings(MCObjectStreamer *Streamer) = 0;
-  virtual void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) = 0;
-
-  static void EmitSectionOffset(MCObjectStreamer *Streamer,
-                                MCSymbol *Symbol,
-                                unsigned Size,
-                                uint32_t Offset = 0);
-
-  static const MCExpr *CreateOffsetExpr(MCContext &Context,
-                                        MCSymbol *BeginSymbol,
-                                        MCSymbol *Symbol);
-
-  static void EmitOffset(MCObjectStreamer *Streamer,
-                         const MCExpr *OffsetExpr,
-                         unsigned Size);
-
-  static void EmitInfoOffset(MCObjectStreamer *Streamer, const DwarfInfo *Info, unsigned Size);
-
-  MCSymbol *StrSymbol;
-  MCSymbol *InfoSymbol;
-  const MCExpr *InfoExpr;
-
-  bool IsDumped;
-  bool IsDumpedTypes;
-};
-
-class DwarfPrimitiveTypeInfo : public DwarfInfo
-{
-public:
-  DwarfPrimitiveTypeInfo(PrimitiveTypeFlags PrimitiveType) : Type(PrimitiveType) {}
-
-  PrimitiveTypeFlags GetType() { return Type; }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  PrimitiveTypeFlags Type;
-};
-
-class DwarfVoidTypeInfo : public DwarfPrimitiveTypeInfo
-{
-public:
-  DwarfVoidTypeInfo() : DwarfPrimitiveTypeInfo(PrimitiveTypeFlags::Void) {}
-
-protected:
-  void DumpStrings(MCObjectStreamer* Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) override;
-};
-
-class DwarfEnumTypeInfo;
-
-class DwarfEnumerator : public DwarfInfo
-{
-public:
-  DwarfEnumerator(const EnumRecordTypeDescriptor &Descriptor, DwarfEnumTypeInfo *TypeInfo) :
-      Name(Descriptor.Name), Value(Descriptor.Value), EnumTypeInfo(TypeInfo) {}
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  std::string Name;
-  uint64 Value;
-  DwarfEnumTypeInfo *EnumTypeInfo;
-};
-
-class DwarfEnumTypeInfo : public DwarfInfo
-{
-public:
-  DwarfEnumTypeInfo(const EnumTypeDescriptor &TypeDescriptor,
-                    const EnumRecordTypeDescriptor *TypeRecords);
-
-  void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-  void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-  uint8_t GetByteSize() const { return ByteSize; }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  std::string Name;
-  uint32_t ElementType;
-  std::vector<DwarfEnumerator> Records;
-  uint8_t ByteSize;
-};
-
-class DwarfDataField : public DwarfInfo
-{
-public:
-  DwarfDataField(const DataFieldDescriptor &Descriptor) :
-      Name(Descriptor.Name),
-      TypeIndex(Descriptor.FieldTypeIndex),
-      Offset(Descriptor.Offset) {}
-
-  void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-  uint32_t GetTypeIndex() const { return TypeIndex; }
-
-  const std::string &GetName() const { return Name; }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-  std::string Name;
-  uint32_t TypeIndex;
-  uint64 Offset;
-};
-
-class DwarfStaticDataField : public DwarfDataField
-{
-public:
-  DwarfStaticDataField(const DataFieldDescriptor &Descriptor,
-                       const StaticDataFieldDescriptor &StaticDescriptor) :
-                       DwarfDataField(Descriptor),
-                       StaticDataName(StaticDescriptor.StaticDataName),
-                       StaticOffset(StaticDescriptor.StaticOffset),
-                       StaticDataInObject(StaticDescriptor.IsStaticDataInObject) {}
-
-  const std::string &GetStaticDataName() const { return StaticDataName; }
-  uint64 GetStaticOffset() const { return StaticOffset; }
-  bool IsStaticDataInObject() const { return StaticDataInObject; }
-
-protected:
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  std::string StaticDataName;
-  uint64 StaticOffset;
-  bool StaticDataInObject;
-};
-
-class DwarfMemberFunctionIdTypeInfo;
-
-class DwarfClassTypeInfo : public DwarfInfo
-{
-public:
-  DwarfClassTypeInfo(const ClassTypeDescriptor &ClassDescriptor) :
-                     Name(ClassDescriptor.Name),
-                     IsStruct(ClassDescriptor.IsStruct),
-                     BaseClassId(ClassDescriptor.BaseClassId),
-                     Size(ClassDescriptor.InstanceSize),
-                     IsForwardDecl(true) {}
-
-  DwarfClassTypeInfo(const ClassTypeDescriptor &ClassDescriptor,
-                     const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-                     const DataFieldDescriptor *FieldsDescriptors,
-                     const StaticDataFieldDescriptor *StaticsDescriptors);
-
-  void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-  void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-  void AddMemberFunction(DwarfMemberFunctionIdTypeInfo* TypeInfo) {
-    MemberFunctions.push_back(TypeInfo);
-  }
-
-  const std::vector<DwarfStaticDataField> &GetStaticFields() const { return StaticFields; }
-
-  const std::string &GetName() const { return Name; }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  std::string Name;
-  bool IsStruct;
-  uint32_t BaseClassId;
-  uint64 Size;
-  bool IsForwardDecl;
-  std::vector<DwarfDataField> Fields;
-  std::vector<DwarfStaticDataField> StaticFields;
-  std::vector<DwarfMemberFunctionIdTypeInfo*> MemberFunctions;
-};
-
-class DwarfSimpleArrayTypeInfo : public DwarfInfo
-{
-public:
-  DwarfSimpleArrayTypeInfo(uint32_t ArrayElementType, uint64_t Size) :
-                           ElementType(ArrayElementType),
-                           Size(Size) {}
-
-  void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  uint32_t ElementType;
-  uint64_t Size;
-};
-
-class DwarfPointerTypeInfo : public DwarfInfo
-{
-public:
-  DwarfPointerTypeInfo(const PointerTypeDescriptor& PointerDescriptor) :
-      TypeDesc(PointerDescriptor) {}
-
-  void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  PointerTypeDescriptor TypeDesc;
-};
-
-class DwarfVoidPtrTypeInfo : public DwarfInfo
-{
-public:
-  DwarfVoidPtrTypeInfo() {}
-
-protected:
-  void DumpStrings(MCObjectStreamer* Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) override;
-};
-
-class DwarfMemberFunctionTypeInfo : public DwarfInfo
-{
-public:
-  DwarfMemberFunctionTypeInfo(const MemberFunctionTypeDescriptor& MemberDescriptor,
-                              uint32_t const *const ArgumentTypes,
-                              bool IsStaticMethod);
-
-  const std::vector<uint32_t> &GetArgTypes() const { return ArgumentTypes; }
-
-  bool IsStatic() const { return IsStaticMethod; }
-
-  uint32_t GetReturnTypeIndex() const { return TypeDesc.ReturnType; }
-
-  uint32_t GetThisPtrTypeIndex() const { return TypeDesc.TypeIndexOfThisPointer; }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  MemberFunctionTypeDescriptor TypeDesc;
-  std::vector<uint32_t> ArgumentTypes;
-  bool IsStaticMethod;
-};
-
-class DwarfMemberFunctionIdTypeInfo : public DwarfInfo
-{
-public:
-  DwarfMemberFunctionIdTypeInfo(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor,
-                                DwarfMemberFunctionTypeInfo *TypeInfo) :
-                                LinkageName(MemberIdDescriptor.Name),
-                                Name(MemberIdDescriptor.Name),
-                                ParentClass(MemberIdDescriptor.ParentClass),
-                                MemberFunctionTypeInfo(TypeInfo),
-                                LinkageNameSymbol(nullptr) {}
-
-  const std::vector<uint32_t> &GetArgTypes() const { return MemberFunctionTypeInfo->GetArgTypes(); }
-
-  void SetLinkageName(const char *Name) { LinkageName = Name; }
-
-  void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer,
-      MCSection *TypeSection, MCSection *StrSection) override;
-
-  bool IsStatic() const { return MemberFunctionTypeInfo->IsStatic(); }
-
-protected:
-  void DumpStrings(MCObjectStreamer *Streamer) override;
-  void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override;
-
-private:
-  std::string LinkageName;
-  std::string Name;
-  uint32_t ParentClass;
-  DwarfMemberFunctionTypeInfo *MemberFunctionTypeInfo;
-  MCSymbol *LinkageNameSymbol;
-};
-
-template<class T>
-class EnumHash
-{
-  typedef typename std::underlying_type<T>::type enumType;
-public:
-  size_t operator()(const T& elem) const {
-    return std::hash<enumType>()(static_cast<enumType>(elem));
-  }
-};
-
-class UserDefinedDwarfTypesBuilder : public UserDefinedTypesBuilder
-{
-public:
-  UserDefinedDwarfTypesBuilder() {}
-  void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) override;
-
-  unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor,
-                            const EnumRecordTypeDescriptor *TypeRecords) override;
-  unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) override;
-  unsigned GetCompleteClassTypeIndex(
-      const ClassTypeDescriptor &ClassDescriptor,
-      const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-      const DataFieldDescriptor *FieldsDescriptors,
-      const StaticDataFieldDescriptor *StaticsDescriptors) override;
-
-  unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor,
-                             const ArrayTypeDescriptor &ArrayDescriptor) override;
-
-  unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) override;
-
-  unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-      uint32_t const *const ArgumentTypes) override;
-
-  unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) override;
-
-  unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) override;
-
-  DwarfInfo *GetTypeInfoByIndex(unsigned Index) const { return DwarfTypes[TypeIndexToArrayIndex(Index)].get(); }
-
-  unsigned GetSimpleArrayTypeIndex(unsigned ElemIndex, unsigned Size);
-
-  const std::vector<DwarfClassTypeInfo*> &GetClassesWithStaticFields() const { return ClassesWithStaticFields; }
-
-private:
-  static const unsigned StartTypeIndex = 1; // Make TypeIndex 0 - Invalid
-  static unsigned TypeIndexToArrayIndex(unsigned TypeIndex) { return TypeIndex - StartTypeIndex; }
-  static unsigned ArrayIndexToTypeIndex(unsigned ArrayIndex) { return ArrayIndex + StartTypeIndex; }
-
-  std::vector<std::unique_ptr<DwarfInfo>> DwarfTypes;
-  std::unordered_map<PrimitiveTypeFlags, uint32_t, EnumHash<PrimitiveTypeFlags>> PrimitiveDwarfTypes;
-  // map[ElemTypeIndex][Size] -> ArrTypeIndex
-  std::unordered_map<uint32_t, std::unordered_map<uint32_t, uint32_t>> SimpleArrayDwarfTypes;
-
-  std::vector<DwarfClassTypeInfo*> ClassesWithStaticFields;
-};
diff --git a/src/coreclr/tools/aot/ObjWriter/debugInfo/typeBuilder.h b/src/coreclr/tools/aot/ObjWriter/debugInfo/typeBuilder.h
deleted file mode 100644 (file)
index 67a5004..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-//===---- typeBuilder.h -----------------------------------------*- C++ -*-===//
-//
-// type builder is used to convert .Net types into debuginfo.
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#pragma once
-
-#include "llvm/MC/MCObjectStreamer.h"
-
-#include <string>
-#include <vector>
-
-using namespace llvm;
-
-// Keep in sync with Internal.TypeSystem.TypeFlags (Common/src/TypeSystem/Common/TypeFlags.cs)
-enum class PrimitiveTypeFlags {
-  Unknown = 0x00,
-  Void    = 0x01,
-  Boolean = 0x02,
-  Char    = 0x03,
-  SByte   = 0x04,
-  Byte    = 0x05,
-  Int16   = 0x06,
-  UInt16  = 0x07,
-  Int32   = 0x08,
-  UInt32  = 0x09,
-  Int64   = 0x0A,
-  UInt64  = 0x0B,
-  IntPtr  = 0x0C,
-  UIntPtr = 0x0D,
-  Single  = 0x0E,
-  Double  = 0x0F
-};
-
-typedef unsigned long long uint64;
-
-#pragma pack(push, 8)
-
-extern "C" struct EnumRecordTypeDescriptor {
-  uint64 Value;
-  const char *Name;
-};
-
-extern "C" struct EnumTypeDescriptor {
-  uint32_t ElementType;
-  uint64 ElementCount;
-  const char *Name;
-};
-
-extern "C" struct ClassTypeDescriptor {
-  int32_t IsStruct;
-  const char *Name;
-  uint32_t BaseClassId;
-  uint64 InstanceSize;
-};
-
-extern "C" struct DataFieldDescriptor {
-  uint32_t FieldTypeIndex;
-  uint64 Offset;
-  const char *Name;
-};
-
-extern "C" struct StaticDataFieldDescriptor {
-  const char *StaticDataName;
-  uint64 StaticOffset;
-  int IsStaticDataInObject;
-};
-
-extern "C" struct ClassFieldsTypeDescriptior {
-  uint64 Size;
-  int32_t FieldsCount;
-};
-
-extern "C" struct ArrayTypeDescriptor {
-  uint32_t Rank;
-  uint32_t ElementType;
-  uint32_t Size; // ElementSize
-  int32_t IsMultiDimensional;
-};
-
-extern "C" struct PointerTypeDescriptor {
-  uint32_t ElementType;
-  int32_t IsReference;
-  int32_t IsConst;
-  int32_t Is64Bit;
-};
-
-extern "C" struct MemberFunctionTypeDescriptor {
-  uint32_t ReturnType;
-  uint32_t ContainingClass;
-  uint32_t TypeIndexOfThisPointer;
-  int32_t ThisAdjust;
-  uint32_t CallingConvention;
-  uint16_t NumberOfArguments;
-};
-
-extern "C" struct MemberFunctionIdTypeDescriptor {
-  uint32_t MemberFunction;
-  uint32_t ParentClass;
-  const char *Name;
-};
-
-#pragma pack(pop)
-class UserDefinedTypesBuilder {
-public:
-  UserDefinedTypesBuilder() : Streamer(nullptr), TargetPointerSize(0) {}
-  virtual ~UserDefinedTypesBuilder() {}
-  void SetStreamer(MCObjectStreamer *Streamer) {
-    assert(this->Streamer == nullptr);
-    assert(Streamer != nullptr);
-    this->Streamer = Streamer;
-  }
-  MCObjectStreamer *GetStreamer() const {
-    return Streamer;
-  }
-  void SetTargetPointerSize(unsigned TargetPointerSize) {
-    assert(this->TargetPointerSize == 0);
-    assert(TargetPointerSize != 0);
-    this->TargetPointerSize = TargetPointerSize;
-  }
-  virtual void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) = 0;
-
-  virtual unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor,
-                                    const EnumRecordTypeDescriptor *TypeRecords) = 0;
-  virtual unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) = 0;
-  virtual unsigned GetCompleteClassTypeIndex(
-      const ClassTypeDescriptor &ClassDescriptor,
-      const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-      const DataFieldDescriptor *FieldsDescriptors,
-      const StaticDataFieldDescriptor *StaticsDescriptors) = 0;
-
-  virtual unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor,
-                                     const ArrayTypeDescriptor &ArrayDescriptor) = 0;
-
-  virtual unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) = 0;
-
-  virtual unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-      uint32_t const *const ArgumentTypes) = 0;
-
-  virtual unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) = 0;
-
-  virtual unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) = 0;
-
-  virtual const std::vector<std::pair<std::string, uint32_t>> &GetUDTs() {
-    return UserDefinedTypes;
-  }
-
-protected:
-  MCObjectStreamer *Streamer;
-  unsigned TargetPointerSize;
-
-  std::vector<std::pair<std::string, uint32_t>> UserDefinedTypes;
-};
diff --git a/src/coreclr/tools/aot/ObjWriter/jitDebugInfo.h b/src/coreclr/tools/aot/ObjWriter/jitDebugInfo.h
deleted file mode 100644 (file)
index 88a96f7..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef JIT_DEBUG_INFO_H
-#define JIT_DEBUG_INFO_H
-
-typedef unsigned int DWORD;
-
-#define PORTABILITY_WARNING(msg)
-#include "cordebuginfo.h"
-
-// RegNum enumeration is architecture-specific and we need it for all
-// architectures we support.
-
-namespace X86 {
-#define TARGET_X86 1
-#include "cordebuginfo.h"
-#undef TARGET_X86
-}
-
-namespace Amd64 {
-#define TARGET_AMD64 1
-#include "cordebuginfo.h"
-#undef TARGET_AMD64
-}
-
-namespace Arm {
-#define TARGET_ARM 1
-#include "cordebuginfo.h"
-#undef TARGET_ARM
-}
-
-namespace Arm64 {
-#define TARGET_ARM64 1
-#include "cordebuginfo.h"
-#undef TARGET_ARM64
-}
-
-struct DebugLocInfo {
-  int NativeOffset;
-  int FileId;
-  int LineNumber;
-  int ColNumber;
-};
-
-struct DebugVarInfo {
-  std::string Name;
-  int TypeIndex;
-  bool IsParam;
-  std::vector<ICorDebugInfo::NativeVarInfo> Ranges;
-
-  DebugVarInfo() {}
-  DebugVarInfo(char *ArgName, int ArgTypeIndex, bool ArgIsParam)
-      : Name(ArgName), TypeIndex(ArgTypeIndex), IsParam(ArgIsParam) {}
-};
-
-struct DebugEHClauseInfo {
-  unsigned TryOffset;
-  unsigned TryLength;
-  unsigned HandlerOffset;
-  unsigned HandlerLength;
-
-  DebugEHClauseInfo(unsigned TryOffset, unsigned TryLength,
-                    unsigned HandlerOffset, unsigned HandlerLength) :
-                    TryOffset(TryOffset), TryLength(TryLength),
-                    HandlerOffset(HandlerOffset), HandlerLength(HandlerLength) {}
-};
-
-#endif // JIT_DEBUG_INFO_H
diff --git a/src/coreclr/tools/aot/ObjWriter/llvm.patch b/src/coreclr/tools/aot/ObjWriter/llvm.patch
deleted file mode 100644 (file)
index 58fa44c..0000000
+++ /dev/null
@@ -1,333 +0,0 @@
-diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
-index a00000bc11b60cae8567ee49da9dd7a4967aac1e..810fe68fc5bf3501c7a3543696485990ea558cb9 100644
---- a/llvm/include/llvm/MC/MCObjectStreamer.h
-+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
-@@ -120,6 +120,11 @@ public:
-   void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
-   void emitValueImpl(const MCExpr *Value, unsigned Size,
-                      SMLoc Loc = SMLoc()) override;
-+  /// \brief EmitValueImpl with additional param, that allows to emit PCRelative
-+  /// MCFixup.
-+  void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc,
-+                     bool isPCRelative);
-+
-   void emitULEB128Value(const MCExpr *Value) override;
-   void emitSLEB128Value(const MCExpr *Value) override;
-   void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
-diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
-index cdc728f7377207f809781e53831fe4e8cc32d82e..8457b465e807bf5b8ee889548074de00a199a81f 100644
---- a/llvm/include/llvm/MC/MCStreamer.h
-+++ b/llvm/include/llvm/MC/MCStreamer.h
-@@ -146,6 +146,7 @@ public:
-   virtual void emitPad(int64_t Offset);
-   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
-                            bool isVector);
-+  virtual void emitLsda(const MCSymbol *Symbol);
-   virtual void emitUnwindRaw(int64_t StackOffset,
-                              const SmallVectorImpl<uint8_t> &Opcodes);
-@@ -669,6 +670,9 @@ public:
-   /// etc.
-   virtual void emitBytes(StringRef Data);
-+  /// \brief Emit the given \p Instruction data into the current section.
-+  virtual void emitInstructionBytes(StringRef Data);
-+
-   /// Functionally identical to EmitBytes. When emitting textual assembly, this
-   /// method uses .byte directives instead of .ascii or .asciz for readability.
-   virtual void emitBinaryData(StringRef Data);
-diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
-index 1c23d31f8744a6f842fa96279daf7ab7770157b1..1c7012bd9b77360d20c860fc6fa198c4cc06e6e5 100644
---- a/llvm/lib/MC/MCObjectStreamer.cpp
-+++ b/llvm/lib/MC/MCObjectStreamer.cpp
-@@ -223,7 +223,7 @@ void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
- }
- void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
--                                     SMLoc Loc) {
-+                                     SMLoc Loc, bool isPCRelative) {
-   MCStreamer::emitValueImpl(Value, Size, Loc);
-   MCDataFragment *DF = getOrCreateDataFragment();
-   flushPendingLabels(DF, DF->getContents().size());
-@@ -243,10 +243,15 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
-   }
-   DF->getFixups().push_back(
-       MCFixup::create(DF->getContents().size(), Value,
--                      MCFixup::getKindForSize(Size, false), Loc));
-+                      MCFixup::getKindForSize(Size, isPCRelative), Loc));
-   DF->getContents().resize(DF->getContents().size() + Size, 0);
- }
-+void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
-+                                     SMLoc Loc) {
-+  emitValueImpl(Value, Size, Loc, false);
-+}
-+
- MCSymbol *MCObjectStreamer::emitCFILabel() {
-   MCSymbol *Label = getContext().createTempSymbol("cfi");
-   emitLabel(Label);
-diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
-index 4b5ae3cc202de943e93ea7f3d84cfe9b47c40baf..623e06fa6ba889c6d0c7cc203821f4411678e39e 100644
---- a/llvm/lib/MC/MCStreamer.cpp
-+++ b/llvm/lib/MC/MCStreamer.cpp
-@@ -1136,6 +1136,7 @@ void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
- void MCStreamer::changeSection(MCSection *, const MCExpr *) {}
- void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
- void MCStreamer::emitBytes(StringRef Data) {}
-+void MCStreamer::emitInstructionBytes(StringRef Data) { emitBytes(Data); }
- void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }
- void MCStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
-   visitUsedExpr(*Value);
-diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
-index 901d2c06e716f0ab05ea18385662ab548fcba9b4..932f487f7dcd612627f6aa205edea86c969d1740 100644
---- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
-+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
-@@ -794,7 +794,9 @@ void WinCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
-   if ((Header.Machine == COFF::IMAGE_FILE_MACHINE_AMD64 &&
-        Reloc.Data.Type == COFF::IMAGE_REL_AMD64_REL32) ||
-       (Header.Machine == COFF::IMAGE_FILE_MACHINE_I386 &&
--       Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32))
-+       Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32) ||
-+      (Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64 &&
-+       Reloc.Data.Type == COFF::IMAGE_REL_ARM64_REL32))
-     FixedValue += 4;
-   if (Header.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
-diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
-index 75a9f2f5c80e3b6c81258084f52237a54f6aad43..73a2d7b2c5bf966bddc0d0435ca6c008bd8bc6c9 100644
---- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
-+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
-@@ -141,6 +141,7 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
-   case AArch64::fixup_aarch64_pcrel_call26:
-   case FK_Data_4:
-   case FK_SecRel_4:
-+  case FK_PCRel_4:
-     return 4;
-   case FK_Data_8:
-@@ -330,13 +331,19 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
-   case FK_Data_8:
-   case FK_SecRel_2:
-   case FK_SecRel_4:
-+  case FK_PCRel_4:
-     return Value;
-   }
- }
- Optional<MCFixupKind> AArch64AsmBackend::getFixupKind(StringRef Name) const {
--  if (!TheTriple.isOSBinFormatELF())
--    return None;
-+  if (!TheTriple.isOSBinFormatELF()) {
-+      return StringSwitch<Optional<MCFixupKind>>(Name)
-+          .Case("R_AARCH64_CALL26", (MCFixupKind)AArch64::fixup_aarch64_pcrel_call26)
-+          .Case("R_AARCH64_ADR_PREL_PG_HI21", (MCFixupKind)AArch64::fixup_aarch64_pcrel_adrp_imm21)
-+          .Case("R_AARCH64_ADD_ABS_LO12_NC", (MCFixupKind)AArch64::fixup_aarch64_add_imm12)
-+          .Default(MCAsmBackend::getFixupKind(Name));
-+  }
-   unsigned Type = llvm::StringSwitch<unsigned>(Name)
- #define ELF_RELOC(X, Y)  .Case(#X, Y)
-diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
-index fcf67bd2f740f5f01454029d0d33c5f1172737f8..c6bcf963f6f89fe6eb7962c3fc0edd08cad94816 100644
---- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
-+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
-@@ -130,6 +130,7 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
-       return ELF::R_AARCH64_NONE;
-     case FK_Data_2:
-       return R_CLS(PREL16);
-+    case FK_PCRel_4:
-     case FK_Data_4: {
-       return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT
-                  ? R_CLS(PLT32)
-diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
-index aaadc8dc1b6001ace9268be68eadb7bd38035304..48ed1e63f6d9bd73a4816e5816b6e34992c5c0a1 100644
---- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
-+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
-@@ -91,6 +91,9 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
-   case FK_Data_8:
-     return COFF::IMAGE_REL_ARM64_ADDR64;
-+  case FK_PCRel_4:
-+    return COFF::IMAGE_REL_ARM64_REL32;
-+
-   case FK_SecRel_2:
-     return COFF::IMAGE_REL_ARM64_SECTION;
-diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
-index b02aef3c338b8fcc4f7d3f110a6a9c5417518c88..f9636aed5068c8fdd20d1b5b2c03e97c9f1b2f20 100644
---- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
-+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
-@@ -448,6 +448,8 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
-   case FK_Data_2:
-   case FK_Data_4:
-     return Value;
-+  case FK_PCRel_4:
-+    return Value;
-   case FK_SecRel_2:
-     return Value;
-   case FK_SecRel_4:
-@@ -967,6 +969,9 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
-   case ARM::fixup_le:
-     return 4;
-+  case FK_PCRel_4:
-+    return 4;
-+
-   case FK_SecRel_2:
-     return 2;
-   case FK_SecRel_4:
-diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
-index 37d81e4b0af13dd0c450849d2a24ab33a5b0c6d1..00a543cc08a9665c42dafa8a863aa41e85705ee9 100644
---- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
-+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
-@@ -111,6 +111,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
-       case MCSymbolRefExpr::VK_ARM_PREL31:
-         return ELF::R_ARM_PREL31;
-       }
-+    case FK_PCRel_4:
-+      return ELF::R_ARM_REL32;
-     case ARM::fixup_arm_blx:
-     case ARM::fixup_arm_uncondbl:
-       switch (Modifier) {
-diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
-index 07ca5c29f0ec995c9f0213a78d3f0f6e386289e0..fa9f498182403136765f29136a1318260c14deb2 100644
---- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
-+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
-@@ -84,6 +84,7 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer {
-   void emitPad(int64_t Offset) override;
-   void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
-                    bool isVector) override;
-+  void emitLsda(const MCSymbol* Symbol) override;
-   void emitUnwindRaw(int64_t Offset,
-                      const SmallVectorImpl<uint8_t> &Opcodes) override;
-@@ -272,6 +273,8 @@ void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
-   OS << '\n';
- }
-+void ARMTargetAsmStreamer::emitLsda(const MCSymbol* Symbol) {}
-+
- class ARMTargetELFStreamer : public ARMTargetStreamer {
- private:
-   // This structure holds all attributes, accounting for
-@@ -388,6 +391,7 @@ private:
-   void emitPad(int64_t Offset) override;
-   void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
-                    bool isVector) override;
-+  void emitLsda(const MCSymbol *Symbol) override;
-   void emitUnwindRaw(int64_t Offset,
-                      const SmallVectorImpl<uint8_t> &Opcodes) override;
-@@ -457,6 +461,7 @@ public:
-   void emitMovSP(unsigned Reg, int64_t Offset = 0);
-   void emitPad(int64_t Offset);
-   void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
-+  void emitLsda(const MCSymbol* Symbol);
-   void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
-   void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
-                 SMLoc Loc) override {
-@@ -536,6 +541,18 @@ public:
-     MCELFStreamer::emitBytes(Data);
-   }
-+  /// This function is the one used to emit instruction data into the ELF
-+  /// streamer. We override it to add the appropriate mapping symbol if
-+  /// necessary.
-+  void emitInstructionBytes(StringRef Data) override {
-+    if (IsThumb)
-+      EmitThumbMappingSymbol();
-+    else
-+      EmitARMMappingSymbol();
-+
-+    MCELFStreamer::emitBytes(Data);
-+  }
-+
-   void FlushPendingMappingSymbol() {
-     if (!LastEMSInfo->hasInfo())
-       return;
-@@ -699,6 +716,7 @@ private:
-   bool CantUnwind;
-   SmallVector<uint8_t, 64> Opcodes;
-   UnwindOpcodeAssembler UnwindOpAsm;
-+  const MCSymbol *Lsda;
- };
- } // end anonymous namespace
-@@ -741,6 +759,10 @@ void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
-   getStreamer().emitRegSave(RegList, isVector);
- }
-+void ARMTargetELFStreamer::emitLsda(const MCSymbol *Symbol) {
-+  getStreamer().emitLsda(Symbol);
-+}
-+
- void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
-                                       const SmallVectorImpl<uint8_t> &Opcodes) {
-   getStreamer().emitUnwindRaw(Offset, Opcodes);
-@@ -1241,6 +1263,7 @@ void ARMELFStreamer::EHReset() {
-   PendingOffset = 0;
-   UsedFP = false;
-   CantUnwind = false;
-+  Lsda = nullptr;
-   Opcodes.clear();
-   UnwindOpAsm.Reset();
-@@ -1343,6 +1366,8 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
-   }
-   // Finalize the unwind opcode sequence
-+  if (Lsda != nullptr && Opcodes.size() <= 4u)
-+    PersonalityIndex = ARM::EHABI::AEABI_UNWIND_CPP_PR1;
-   UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
-   // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
-@@ -1387,7 +1412,13 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
-   //
-   // In case that the .handlerdata directive is not specified by the
-   // programmer, we should emit zero to terminate the handler data.
--  if (NoHandlerData && !Personality)
-+  if (Lsda != nullptr) {
-+    const MCSymbolRefExpr *LsdaRef =
-+      MCSymbolRefExpr::create(Lsda,
-+                              MCSymbolRefExpr::VK_None,
-+                              getContext());
-+    emitValue(LsdaRef, 4);
-+  } else if (NoHandlerData && !Personality)
-     emitInt32(0);
- }
-@@ -1470,6 +1501,10 @@ void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
-     UnwindOpAsm.EmitRegSave(Mask);
- }
-+void ARMELFStreamer::emitLsda(const MCSymbol *Symbol) {
-+  Lsda = Symbol;
-+}
-+
- void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
-                                    const SmallVectorImpl<uint8_t> &Opcodes) {
-   FlushPendingOffset();
-diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
-index 1fee354cad93266060222bec3ed6ceef3d310e54..7d2eb8ef5e367372466c0bf1fb7d98494a00cfcd 100644
---- a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
-+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
-@@ -97,6 +97,7 @@ void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {}
- void ARMTargetStreamer::emitPad(int64_t Offset) {}
- void ARMTargetStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
-                                     bool isVector) {}
-+void ARMTargetStreamer::emitLsda(const MCSymbol *Symbol) {}
- void ARMTargetStreamer::emitUnwindRaw(int64_t StackOffset,
-                                       const SmallVectorImpl<uint8_t> &Opcodes) {
- }
-diff --git a/llvm/tools/CMakeLists.txt b/llvm/tools/CMakeLists.txt
-index b6d3b2c2fcbeb1f3c9ec041766ae60604ec2db64..491715166e96527b09d3299f35615fd9f8ad5fd8 100644
---- a/llvm/tools/CMakeLists.txt
-+++ b/llvm/tools/CMakeLists.txt
-@@ -39,6 +39,7 @@ add_llvm_external_project(lldb)
- add_llvm_external_project(mlir)
- # Flang depends on mlir, so place it afterward
- add_llvm_external_project(flang)
-+add_llvm_external_project(ObjWriter)
- # Automatically add remaining sub-directories containing a 'CMakeLists.txt'
- # file as external projects.
diff --git a/src/coreclr/tools/aot/ObjWriter/objwriter.cpp b/src/coreclr/tools/aot/ObjWriter/objwriter.cpp
deleted file mode 100644 (file)
index 3e44a8b..0000000
+++ /dev/null
@@ -1,1130 +0,0 @@
-//===---- objwriter.cpp -----------------------------------------*- C++ -*-===//
-//
-// object writer
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief Implementation of object writer API for JIT/AOT
-///
-//===----------------------------------------------------------------------===//
-
-#include "objwriter.h"
-#include "debugInfo/dwarf/dwarfTypeBuilder.h"
-#include "debugInfo/codeView/codeViewTypeBuilder.h"
-#include "cvconst.h"
-#include "llvm/DebugInfo/CodeView/CodeView.h"
-#include "llvm/DebugInfo/CodeView/Line.h"
-#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
-#include "llvm/MC/MCAsmBackend.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCCodeEmitter.h"
-#include "llvm/MC/MCDwarf.h"
-#include "llvm/MC/MCInstPrinter.h"
-#include "llvm/MC/MCInstrInfo.h"
-#include "llvm/MC/MCParser/AsmLexer.h"
-#include "llvm/MC/MCParser/MCTargetAsmParser.h"
-#include "llvm/MC/MCRegisterInfo.h"
-#include "llvm/MC/MCSectionCOFF.h"
-#include "llvm/MC/MCSectionELF.h"
-#include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MCObjectStreamer.h"
-#include "llvm/MC/MCObjectWriter.h"
-#include "llvm/MC/MCSubtargetInfo.h"
-#include "llvm/MC/MCTargetOptionsCommandFlags.h"
-#include "llvm/MC/MCELFStreamer.h"
-#include "llvm/BinaryFormat/COFF.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Compression.h"
-#include "llvm/BinaryFormat/ELF.h"
-#include "llvm/Support/FileUtilities.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/Host.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/TargetSelect.h"
-#include "llvm/Support/ToolOutputFile.h"
-#include "llvm/Support/Win64EH.h"
-#include "llvm/Target/TargetMachine.h"
-#include "../../../lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h"
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-bool error(const Twine &Error) {
-  errs() << Twine("error: ") + Error + "\n";
-  return false;
-}
-
-void ObjectWriter::InitTripleName(const char* tripleName) {
-  TripleName = tripleName != nullptr ? tripleName : sys::getDefaultTargetTriple();
-}
-
-Triple ObjectWriter::GetTriple() {
-  Triple TheTriple(TripleName);
-
-  if (TheTriple.getOS() == Triple::OSType::Darwin) {
-    TheTriple = Triple(
-        TheTriple.getArchName(), TheTriple.getVendorName(), "darwin",
-        TheTriple
-            .getEnvironmentName()); // it is workaround for llvm bug
-                                    // https://bugs.llvm.org//show_bug.cgi?id=24927.
-  }
-  return TheTriple;
-}
-
-bool ObjectWriter::Init(llvm::StringRef ObjectFilePath, const char* tripleName) {
-  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
-  // Initialize targets
-  InitializeAllTargetInfos();
-  InitializeAllTargetMCs();
-
-  InitTripleName(tripleName);
-  Triple TheTriple = GetTriple();
-
-  // Get the target specific parser.
-  std::string TargetError;
-  const Target *TheTarget =
-      TargetRegistry::lookupTarget(TripleName, TargetError);
-  if (!TheTarget) {
-    return error("Unable to create target for " + ObjectFilePath + ": " +
-                 TargetError);
-  }
-
-  std::error_code EC;
-  OS.reset(new raw_fd_ostream(ObjectFilePath, EC, sys::fs::F_None));
-  if (EC)
-    return error("Unable to create file for " + ObjectFilePath + ": " +
-                 EC.message());
-
-  RegisterInfo.reset(TheTarget->createMCRegInfo(TripleName));
-  if (!RegisterInfo)
-    return error("Unable to create target register info!");
-
-  AsmInfo.reset(TheTarget->createMCAsmInfo(*RegisterInfo, TripleName, TargetMOptions));
-  if (!AsmInfo)
-    return error("Unable to create target asm info!");
-
-  ObjFileInfo.reset(new MCObjectFileInfo);
-  OutContext.reset(
-      new MCContext(AsmInfo.get(), RegisterInfo.get(), ObjFileInfo.get()));
-  ObjFileInfo->InitMCObjectFileInfo(TheTriple, false,
-                                    *OutContext);
-
-  InstrInfo.reset(TheTarget->createMCInstrInfo());
-  if (!InstrInfo)
-    return error("no instr info info for target " + TripleName);
-
-  std::string FeaturesStr;
-  std::string MCPU;
-  SubtargetInfo.reset(
-      TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
-  if (!SubtargetInfo)
-    return error("no subtarget info for target " + TripleName);
-
-  CodeEmitter =
-      TheTarget->createMCCodeEmitter(*InstrInfo, *RegisterInfo, *OutContext);
-  if (!CodeEmitter)
-    return error("no code emitter for target " + TripleName);
-
-  AsmBackend = TheTarget->createMCAsmBackend(*SubtargetInfo, *RegisterInfo, TargetMOptions);
-  if (!AsmBackend)
-    return error("no asm backend for target " + TripleName);
-
-  Streamer = (MCObjectStreamer *)TheTarget->createMCObjectStreamer(
-      TheTriple, *OutContext, std::unique_ptr<MCAsmBackend>(AsmBackend), AsmBackend->createObjectWriter(*OS),
-      std::unique_ptr<MCCodeEmitter>(CodeEmitter), *SubtargetInfo,
-      /*RelaxAll*/ true,
-      /*IncrementalLinkerCompatible*/ false,
-      /*DWARFMustBeAtTheEnd*/ false);
-  if (!Streamer)
-    return error("no object streamer for target " + TripleName);
-  Assembler = &Streamer->getAssembler();
-
-  FrameOpened = false;
-  FuncId = 1;
-
-  SetCodeSectionAttribute("text", CustomSectionAttributes_Executable, nullptr);
-
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF) {
-    TypeBuilder.reset(new UserDefinedCodeViewTypesBuilder());
-  } else {
-    TypeBuilder.reset(new UserDefinedDwarfTypesBuilder());
-  }
-
-  TypeBuilder->SetStreamer(Streamer);
-  unsigned TargetPointerSize = Streamer->getContext().getAsmInfo()->getCodePointerSize();
-  TypeBuilder->SetTargetPointerSize(TargetPointerSize);
-
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsELF) {
-    DwarfGenerator.reset(new DwarfGen());
-    DwarfGenerator->SetTypeBuilder(static_cast<UserDefinedDwarfTypesBuilder*>(TypeBuilder.get()));
-  }
-
-  CFIsPerOffset.set_size(0);
-
-  return true;
-}
-
-void ObjectWriter::Finish() {
-
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF
-    && AddressTakenFunctions.size() > 0) {
-
-    // Emit all address-taken functions into the GFIDs section
-    // to support control flow guard.
-    Streamer->SwitchSection(ObjFileInfo->getGFIDsSection());
-    for (const MCSymbol* S : AddressTakenFunctions) {
-      Streamer->EmitCOFFSymbolIndex(S);
-    }
-
-    // Emit the feat.00 symbol that controls various linker behaviors
-    MCSymbol* S = OutContext->getOrCreateSymbol(StringRef("@feat.00"));
-    Streamer->BeginCOFFSymbolDef(S);
-    Streamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
-    Streamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
-    Streamer->EndCOFFSymbolDef();
-    int64_t Feat00Flags = 0;
-
-    Feat00Flags |= 0x800; // cfGuardCF flags this object as control flow guard aware
-
-    Streamer->emitSymbolAttribute(S, MCSA_Global);
-    Streamer->emitAssignment(
-      S, MCConstantExpr::create(Feat00Flags, *OutContext));
-  }
-
-  Streamer->Finish();
-}
-
-void ObjectWriter::SwitchSection(const char *SectionName,
-                                 CustomSectionAttributes attributes,
-                                 const char *ComdatName) {
-  MCSection *Section = GetSection(SectionName, attributes, ComdatName);
-  Streamer->SwitchSection(Section);
-  if (Sections.count(Section) == 0) {
-    Sections.insert(Section);
-    if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsMachO) {
-      assert(!Section->getBeginSymbol());
-      // Output a DWARF linker-local symbol.
-      // This symbol is used as a base for other symbols in a section.
-      MCSymbol *SectionStartSym = OutContext->createTempSymbol();
-      Streamer->emitLabel(SectionStartSym);
-      Section->setBeginSymbol(SectionStartSym);
-    }
-  }
-}
-
-MCSection *ObjectWriter::GetSection(const char *SectionName,
-                                    CustomSectionAttributes attributes,
-                                    const char *ComdatName) {
-  MCSection *Section = nullptr;
-
-  if (strcmp(SectionName, "text") == 0) {
-    Section = ObjFileInfo->getTextSection();
-  } else if (strcmp(SectionName, "data") == 0) {
-    Section = ObjFileInfo->getDataSection();
-  } else if (strcmp(SectionName, "rdata") == 0) {
-    Section = ObjFileInfo->getReadOnlySection();
-  } else if (strcmp(SectionName, "xdata") == 0) {
-    Section = ObjFileInfo->getXDataSection();
-  } else if (strcmp(SectionName, "bss") == 0) {
-    if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsMachO) {
-      Section = ObjFileInfo->getDataBSSSection();
-    } else {
-      Section = ObjFileInfo->getBSSSection();
-    } 
-  } else {
-    Section = GetSpecificSection(SectionName, attributes, ComdatName);
-  }
-  assert(Section);
-  return Section;
-}
-
-MCSection *ObjectWriter::GetSpecificSection(const char *SectionName,
-                                            CustomSectionAttributes attributes,
-                                            const char *ComdatName) {
-  Triple TheTriple(TripleName);
-  MCSection *Section = nullptr;
-  SectionKind Kind = (attributes & CustomSectionAttributes_Executable)
-                         ? SectionKind::getText()
-                         : (attributes & CustomSectionAttributes_Writeable)
-                               ? SectionKind::getData()
-                               : SectionKind::getReadOnly();
-  switch (TheTriple.getObjectFormat()) {
-  case Triple::MachO: {
-    unsigned typeAndAttributes = 0;
-    if (attributes & CustomSectionAttributes_MachO_Init_Func_Pointers) {
-      typeAndAttributes |= MachO::SectionType::S_MOD_INIT_FUNC_POINTERS;
-    }
-    Section = OutContext->getMachOSection(
-        (attributes & CustomSectionAttributes_Executable) ? "__TEXT" : "__DATA",
-        SectionName, typeAndAttributes, Kind);
-    break;
-  }
-  case Triple::COFF: {
-    unsigned Characteristics = COFF::IMAGE_SCN_MEM_READ;
-
-    if (attributes & CustomSectionAttributes_Executable) {
-      Characteristics |= COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE;
-    } else if (attributes & CustomSectionAttributes_Writeable) {
-      Characteristics |=
-          COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_WRITE;
-    } else {
-      Characteristics |= COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
-    }
-
-    if (ComdatName != nullptr) {
-      Section = OutContext->getCOFFSection(
-          SectionName, Characteristics | COFF::IMAGE_SCN_LNK_COMDAT, Kind,
-          ComdatName, COFF::COMDATType::IMAGE_COMDAT_SELECT_ANY);
-    } else {
-      Section = OutContext->getCOFFSection(SectionName, Characteristics, Kind);
-    }
-    break;
-  }
-  case Triple::ELF: {
-    unsigned Flags = ELF::SHF_ALLOC;
-    if (ComdatName != nullptr) {
-      MCSymbolELF *GroupSym =
-          cast<MCSymbolELF>(OutContext->getOrCreateSymbol(ComdatName));
-      OutContext->createELFGroupSection(GroupSym);
-      Flags |= ELF::SHF_GROUP;
-    }
-    if (attributes & CustomSectionAttributes_Executable) {
-      Flags |= ELF::SHF_EXECINSTR;
-    } else if (attributes & CustomSectionAttributes_Writeable) {
-      Flags |= ELF::SHF_WRITE;
-    }
-    Section =
-        OutContext->getELFSection(SectionName, ELF::SHT_PROGBITS, Flags, 0,
-                                  ComdatName != nullptr ? ComdatName : "");
-    break;
-  }
-  default:
-    error("Unknown output format for target " + TripleName);
-    break;
-  }
-  return Section;
-}
-
-void ObjectWriter::SetCodeSectionAttribute(const char *SectionName,
-                                           CustomSectionAttributes attributes,
-                                           const char *ComdatName) {
-  MCSection *Section = GetSection(SectionName, attributes, ComdatName);
-
-  assert(!Section->hasInstructions());
-  Section->setHasInstructions(true);
-  if (ObjFileInfo->getObjectFileType() != ObjFileInfo->IsCOFF) {
-    OutContext->addGenDwarfSection(Section);
-  }
-}
-
-void ObjectWriter::EmitAlignment(int ByteAlignment) {
-  int64_t fillValue = 0;
-
-  if (Streamer->getCurrentSectionOnly()->getKind().isText()) {
-    if (ObjFileInfo->getTargetTriple().getArch() == llvm::Triple::ArchType::x86 ||
-        ObjFileInfo->getTargetTriple().getArch() == llvm::Triple::ArchType::x86_64) {
-      fillValue = 0x90; // x86 nop
-    }
-  }
-
-  Streamer->emitValueToAlignment(ByteAlignment, fillValue);
-}
-
-void ObjectWriter::EmitBlob(int BlobSize, const char *Blob) {
-  if (Streamer->getCurrentSectionOnly()->getKind().isText()) {
-    Streamer->emitInstructionBytes(StringRef(Blob, BlobSize));
-  } else {
-    Streamer->emitBytes(StringRef(Blob, BlobSize));
-  }
-}
-
-void ObjectWriter::EmitIntValue(uint64_t Value, unsigned Size) {
-  Streamer->emitIntValue(Value, Size);
-}
-
-void ObjectWriter::EmitSymbolDef(const char *SymbolName, bool global) {
-  MCSymbol *Sym = OutContext->getOrCreateSymbol(Twine(SymbolName));
-
-  Streamer->emitSymbolAttribute(Sym, MCSA_Global);
-
-  Triple TheTriple = ObjFileInfo->getTargetTriple();
-
-  if (TheTriple.getObjectFormat() == Triple::ELF) {
-    // An ARM function symbol should be marked with an appropriate ELF attribute
-    // to make later computation of a relocation address value correct
-    if (Streamer->getCurrentSectionOnly()->getKind().isText()) {
-      switch (TheTriple.getArch()) {
-      case Triple::arm:
-      case Triple::armeb:
-      case Triple::thumb:
-      case Triple::thumbeb:
-      case Triple::aarch64:
-      case Triple::aarch64_be:
-        Streamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
-        break;
-      default:
-        break;
-      }
-    }
-
-    // Mark the symbol hidden if requested
-    if (!global) {
-      Streamer->emitSymbolAttribute(Sym, MCSA_Hidden);
-    }
-  }
-
-  Streamer->emitLabel(Sym);
-}
-
-const MCSymbolRefExpr *
-ObjectWriter::GetSymbolRefExpr(const char *SymbolName,
-                               MCSymbolRefExpr::VariantKind Kind) {
-  // Create symbol reference
-  MCSymbol *T = OutContext->getOrCreateSymbol(SymbolName);
-  Assembler->registerSymbol(*T);
-  return MCSymbolRefExpr::create(T, Kind, *OutContext);
-}
-
-unsigned ObjectWriter::GetDFSize() {
-  return Streamer->getOrCreateDataFragment()->getContents().size();
-}
-
-void ObjectWriter::EmitRelocDirective(const int Offset, StringRef Name, const MCExpr *Expr) {
-  const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, *OutContext);
-  Optional<std::pair<bool, std::string>> result = Streamer->emitRelocDirective(*OffsetExpr, Name, Expr, SMLoc(), *SubtargetInfo);
-  assert(!result.hasValue());
-}
-
-const MCExpr *ObjectWriter::GenTargetExpr(const MCSymbol* Symbol, MCSymbolRefExpr::VariantKind Kind,
-                                          int Delta, bool IsPCRel, int Size) {
-  const MCExpr *TargetExpr = MCSymbolRefExpr::create(Symbol, Kind, *OutContext);
-  if (IsPCRel && Size != 0) {
-    // If the fixup is pc-relative, we need to bias the value to be relative to
-    // the start of the field, not the end of the field
-    TargetExpr = MCBinaryExpr::createSub(
-        TargetExpr, MCConstantExpr::create(Size, *OutContext), *OutContext);
-  }
-  if (Delta != 0) {
-    TargetExpr = MCBinaryExpr::createAdd(
-        TargetExpr, MCConstantExpr::create(Delta, *OutContext), *OutContext);
-  }
-  return TargetExpr;
-}
-
-int ObjectWriter::EmitSymbolRef(const char *SymbolName,
-                                RelocType RelocationType, int Delta, SymbolRefFlags Flags) {
-  bool IsPCRel = false;
-  int Size = 0;
-  MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
-
-  MCSymbol* Symbol = OutContext->getOrCreateSymbol(SymbolName);
-  Assembler->registerSymbol(*Symbol);
-
-  if ((int)Flags & (int)SymbolRefFlags::SymbolRefFlags_AddressTakenFunction) {
-    AddressTakenFunctions.insert(Symbol);
-  }
-
-  // Convert RelocationType to MCSymbolRefExpr
-  switch (RelocationType) {
-  case RelocType::IMAGE_REL_BASED_ABSOLUTE:
-    assert(ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF);
-    Kind = MCSymbolRefExpr::VK_COFF_IMGREL32;
-    Size = 4;
-    break;
-  case RelocType::IMAGE_REL_BASED_HIGHLOW:
-    Size = 4;
-    break;
-  case RelocType::IMAGE_REL_BASED_DIR64:
-    Size = 8;
-    break;
-  case RelocType::IMAGE_REL_BASED_REL32:
-    Size = 4;
-    IsPCRel = true;
-    if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsELF) {
-      // PLT is valid only for code symbols,
-      // but there shouldn't be references to global data symbols
-      Kind = MCSymbolRefExpr::VK_PLT;
-    }
-    break;
-  case RelocType::IMAGE_REL_BASED_RELPTR32:
-    Size = 4;
-    IsPCRel = true;
-    Delta += 4;
-    break;
-  case RelocType::IMAGE_REL_BASED_THUMB_MOV32: {
-    const unsigned Offset = GetDFSize();
-    const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta);
-    EmitRelocDirective(Offset, "R_ARM_THM_MOVW_ABS_NC", TargetExpr);
-    EmitRelocDirective(Offset + 4, "R_ARM_THM_MOVT_ABS", TargetExpr);
-    return 8;
-  }
-  case RelocType::IMAGE_REL_BASED_THUMB_BRANCH24: {
-    const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta);
-    EmitRelocDirective(GetDFSize(), "R_ARM_THM_CALL", TargetExpr);
-    return 4;
-  }
-  case RelocType::IMAGE_REL_BASED_ARM64_BRANCH26: {
-    const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta);
-    EmitRelocDirective(GetDFSize(), "R_AARCH64_CALL26", TargetExpr);
-    return 4;
-  }
-  case RelocType::IMAGE_REL_BASED_ARM64_PAGEBASE_REL21: {
-    const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta);
-    TargetExpr =
-        AArch64MCExpr::create(TargetExpr, AArch64MCExpr::VK_CALL, *OutContext);
-    EmitRelocDirective(GetDFSize(), "R_AARCH64_ADR_PREL_PG_HI21", TargetExpr);
-    return 4;
-  }
-  case RelocType::IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A: {
-    const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta);
-    TargetExpr =
-        AArch64MCExpr::create(TargetExpr, AArch64MCExpr::VK_LO12, *OutContext);
-    EmitRelocDirective(GetDFSize(), "R_AARCH64_ADD_ABS_LO12_NC", TargetExpr);
-    return 4;
-  }
-  }
-
-  const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta, IsPCRel, Size);
-  Streamer->emitValueImpl(TargetExpr, Size, SMLoc(), IsPCRel);
-  return Size;
-}
-
-void ObjectWriter::EmitWinFrameInfo(const char *FunctionName, int StartOffset,
-                                    int EndOffset, const char *BlobSymbolName) {
-  assert(ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF);
-
-  // .pdata emission
-  MCSection *Section = ObjFileInfo->getPDataSection();
-
-  // If the function was emitted to a Comdat section, create an associative
-  // section to place the frame info in. This is due to the Windows linker
-  // requirement that a function and its unwind info come from the same
-  // object file.
-  MCSymbol *Fn = OutContext->getOrCreateSymbol(Twine(FunctionName));
-  const MCSectionCOFF *FunctionSection = cast<MCSectionCOFF>(&Fn->getSection());
-  if (FunctionSection->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
-    Section = OutContext->getAssociativeCOFFSection(
-        cast<MCSectionCOFF>(Section), FunctionSection->getCOMDATSymbol());
-  }
-
-  Streamer->SwitchSection(Section);
-  Streamer->emitValueToAlignment(4);
-
-  const MCExpr *BaseRefRel =
-      GetSymbolRefExpr(FunctionName, MCSymbolRefExpr::VK_COFF_IMGREL32);
-
-  Triple::ArchType Arch = ObjFileInfo->getTargetTriple().getArch();
-
-  if (Arch == Triple::thumb || Arch == Triple::thumbeb) {
-    StartOffset |= 1;
-  }
-
-  // start Offset
-  const MCExpr *StartOfs = MCConstantExpr::create(StartOffset, *OutContext);
-  Streamer->emitValue(
-      MCBinaryExpr::createAdd(BaseRefRel, StartOfs, *OutContext), 4);
-
-  if (Arch == Triple::x86 || Arch == Triple::x86_64) {
-    // end Offset
-    const MCExpr *EndOfs = MCConstantExpr::create(EndOffset, *OutContext);
-    Streamer->emitValue(
-        MCBinaryExpr::createAdd(BaseRefRel, EndOfs, *OutContext), 4);
-  }
-
-  // frame symbol reference
-  Streamer->emitValue(
-      GetSymbolRefExpr(BlobSymbolName, MCSymbolRefExpr::VK_COFF_IMGREL32), 4);
-}
-
-void ObjectWriter::EmitCFIStart(int Offset) {
-  assert(!FrameOpened && "frame should be closed before CFIStart");
-  Streamer->emitCFIStartProc(false);
-  FrameOpened = true;
-}
-
-void ObjectWriter::EmitCFIEnd(int Offset) {
-  assert(FrameOpened && "frame should be opened before CFIEnd");
-  Streamer->emitCFIEndProc();
-  FrameOpened = false;
-}
-
-void ObjectWriter::EmitCFILsda(const char *LsdaBlobSymbolName) {
-  assert(FrameOpened && "frame should be opened before CFILsda");
-
-  // Create symbol reference
-  MCSymbol *T = OutContext->getOrCreateSymbol(LsdaBlobSymbolName);
-  Assembler->registerSymbol(*T);
-  Streamer->emitCFILsda(T, llvm::dwarf::Constants::DW_EH_PE_pcrel |
-                               llvm::dwarf::Constants::DW_EH_PE_sdata4);
-}
-
-void ObjectWriter::EmitCFICode(int Offset, const char *Blob) {
-  assert(FrameOpened && "frame should be opened before CFICode");
-
-  const CFI_CODE *CfiCode = (const CFI_CODE *)Blob;
-  switch (CfiCode->CfiOpCode) {
-  case CFI_ADJUST_CFA_OFFSET:
-    assert(CfiCode->DwarfReg == DWARF_REG_ILLEGAL &&
-           "Unexpected Register Value for OpAdjustCfaOffset");
-    Streamer->emitCFIAdjustCfaOffset(CfiCode->Offset);
-    break;
-  case CFI_REL_OFFSET:
-    Streamer->emitCFIRelOffset(CfiCode->DwarfReg, CfiCode->Offset);
-    break;
-  case CFI_DEF_CFA_REGISTER:
-    assert(CfiCode->Offset == 0 &&
-           "Unexpected Offset Value for OpDefCfaRegister");
-    Streamer->emitCFIDefCfaRegister(CfiCode->DwarfReg);
-    break;
-  case CFI_DEF_CFA:
-    assert(CfiCode->Offset != 0 &&
-           "Unexpected Offset Value for OpDefCfa");
-    Streamer->emitCFIDefCfa(CfiCode->DwarfReg, CfiCode->Offset);
-    break;
-  default:
-    assert(false && "Unrecognized CFI");
-    break;
-  }
-}
-
-void ObjectWriter::EmitLabelDiff(const MCSymbol *From, const MCSymbol *To,
-                                 unsigned int Size) {
-  MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
-  const MCExpr *FromRef = MCSymbolRefExpr::create(From, Variant, *OutContext),
-               *ToRef = MCSymbolRefExpr::create(To, Variant, *OutContext);
-  const MCExpr *AddrDelta =
-      MCBinaryExpr::create(MCBinaryExpr::Sub, ToRef, FromRef, *OutContext);
-  Streamer->emitValue(AddrDelta, Size);
-}
-
-void ObjectWriter::EmitSymRecord(int Size, SymbolRecordKind SymbolKind) {
-  RecordPrefix Rec;
-  Rec.RecordLen = ulittle16_t(Size + sizeof(ulittle16_t));
-  Rec.RecordKind = ulittle16_t((uint16_t)SymbolKind);
-  Streamer->emitBytes(StringRef((char *)&Rec, sizeof(Rec)));
-}
-
-void ObjectWriter::EmitCOFFSecRel32Value(MCExpr const *Value) {
-  MCDataFragment *DF = Streamer->getOrCreateDataFragment();
-  MCFixup Fixup = MCFixup::create(DF->getContents().size(), Value, FK_SecRel_4);
-  DF->getFixups().push_back(Fixup);
-  DF->getContents().resize(DF->getContents().size() + 4, 0);
-}
-
-void ObjectWriter::EmitVarDefRange(const MCSymbol *Fn,
-                                   const LocalVariableAddrRange &Range) {
-  const MCSymbolRefExpr *BaseSym = MCSymbolRefExpr::create(Fn, *OutContext);
-  const MCExpr *Offset = MCConstantExpr::create(Range.OffsetStart, *OutContext);
-  const MCExpr *Expr = MCBinaryExpr::createAdd(BaseSym, Offset, *OutContext);
-  EmitCOFFSecRel32Value(Expr);
-  Streamer->EmitCOFFSectionIndex(Fn);
-  Streamer->emitIntValue(Range.Range, 2);
-}
-
-// Maps an ICorDebugInfo register number to the corresponding CodeView
-// register number
-CVRegNum ObjectWriter::GetCVRegNum(unsigned RegNum) {
-  static const CVRegNum CVRegMapAmd64[] = {
-    CV_AMD64_RAX, CV_AMD64_RCX, CV_AMD64_RDX, CV_AMD64_RBX,
-    CV_AMD64_RSP, CV_AMD64_RBP, CV_AMD64_RSI, CV_AMD64_RDI,
-    CV_AMD64_R8, CV_AMD64_R9, CV_AMD64_R10, CV_AMD64_R11,
-    CV_AMD64_R12, CV_AMD64_R13, CV_AMD64_R14, CV_AMD64_R15,
-  };
-
-  switch (ObjFileInfo->getTargetTriple().getArch()) {
-  case Triple::x86:
-    if (X86::ICorDebugInfo::REGNUM_EAX <= RegNum &&
-        RegNum <= X86::ICorDebugInfo::REGNUM_EDI) {
-      return RegNum - X86::ICorDebugInfo::REGNUM_EAX + CV_REG_EAX;
-    }
-    break;
-  case Triple::x86_64:
-    if (RegNum < sizeof(CVRegMapAmd64) / sizeof(CVRegMapAmd64[0])) {
-      return CVRegMapAmd64[RegNum];
-    }
-    break;
-  case Triple::arm:
-  case Triple::armeb:
-  case Triple::thumb:
-  case Triple::thumbeb:
-    if (Arm::ICorDebugInfo::REGNUM_R0 <= RegNum &&
-        RegNum <= Arm::ICorDebugInfo::REGNUM_PC) {
-      return RegNum - Arm::ICorDebugInfo::REGNUM_R0 + CV_ARM_R0;
-    }
-    break;
-  case Triple::aarch64:
-  case Triple::aarch64_be:
-    if (Arm64::ICorDebugInfo::REGNUM_X0 <= RegNum &&
-        RegNum < Arm64::ICorDebugInfo::REGNUM_PC) {
-      return RegNum - Arm64::ICorDebugInfo::REGNUM_X0 + CV_ARM64_X0;
-    }
-    // Special registers are ordered FP, LR, SP, PC in ICorDebugInfo's
-    // enumeration and FP, LR, SP, *ZR*, PC in CodeView's enumeration.
-    // For that reason handle the PC register separately.
-    if (RegNum == Arm64::ICorDebugInfo::REGNUM_PC) {
-      return CV_ARM64_PC;
-    }
-    break;
-  default:
-    assert(false && "Unexpected architecture");
-    break;
-  }
-  return CV_REG_NONE;
-}
-
-void ObjectWriter::EmitCVDebugVarInfo(const MCSymbol *Fn,
-                                      const DebugVarInfo LocInfos[],
-                                      int NumVarInfos) {
-  for (int I = 0; I < NumVarInfos; I++) {
-    // Emit an S_LOCAL record
-    DebugVarInfo Var = LocInfos[I];
-    TypeIndex Type = TypeIndex(Var.TypeIndex);
-    LocalSymFlags Flags = LocalSymFlags::None;
-    unsigned SizeofSym = sizeof(Type) + sizeof(Flags);
-    unsigned NameLength = Var.Name.length() + 1;
-    EmitSymRecord(SizeofSym + NameLength, SymbolRecordKind::LocalSym);
-    if (Var.IsParam) {
-      Flags |= LocalSymFlags::IsParameter;
-    }
-    Streamer->emitBytes(StringRef((char *)&Type, sizeof(Type)));
-    Streamer->emitIntValue(static_cast<uint16_t>(Flags), sizeof(Flags));
-    Streamer->emitBytes(StringRef(Var.Name.c_str(), NameLength));
-
-    for (const auto &Range : Var.Ranges) {
-      // Emit a range record
-      switch (Range.loc.vlType) {
-      case ICorDebugInfo::VLT_REG:
-      case ICorDebugInfo::VLT_REG_FP: {
-
-        // Currently only support integer registers.
-        // TODO: support xmm registers
-        CVRegNum CVReg = GetCVRegNum(Range.loc.vlReg.vlrReg);
-        if (CVReg == CV_REG_NONE) {
-          break;
-        }
-        SymbolRecordKind SymbolKind = SymbolRecordKind::DefRangeRegisterSym;
-        unsigned SizeofDefRangeRegisterSym = sizeof(DefRangeRegisterSym::Hdr) +
-                                             sizeof(DefRangeRegisterSym::Range);
-        EmitSymRecord(SizeofDefRangeRegisterSym, SymbolKind);
-
-        DefRangeRegisterSym DefRangeRegisterSymbol(SymbolKind);
-        DefRangeRegisterSymbol.Range.OffsetStart = Range.startOffset;
-        DefRangeRegisterSymbol.Range.Range =
-            Range.endOffset - Range.startOffset;
-        DefRangeRegisterSymbol.Range.ISectStart = 0;
-        DefRangeRegisterSymbol.Hdr.Register = CVReg;
-        DefRangeRegisterSymbol.Hdr.MayHaveNoName = 0;
-
-        unsigned Length = sizeof(DefRangeRegisterSymbol.Hdr);
-        Streamer->emitBytes(
-            StringRef((char *)&DefRangeRegisterSymbol.Hdr, Length));
-        EmitVarDefRange(Fn, DefRangeRegisterSymbol.Range);
-        break;
-      }
-
-      case ICorDebugInfo::VLT_STK: {
-
-        // TODO: support REGNUM_AMBIENT_SP
-        CVRegNum CVReg = GetCVRegNum(Range.loc.vlStk.vlsBaseReg);
-        if (CVReg == CV_REG_NONE) {
-          break;
-        }
-
-        SymbolRecordKind SymbolKind = SymbolRecordKind::DefRangeRegisterRelSym;
-        unsigned SizeofDefRangeRegisterRelSym =
-            sizeof(DefRangeRegisterRelSym::Hdr) +
-            sizeof(DefRangeRegisterRelSym::Range);
-        EmitSymRecord(SizeofDefRangeRegisterRelSym, SymbolKind);
-
-        DefRangeRegisterRelSym DefRangeRegisterRelSymbol(SymbolKind);
-        DefRangeRegisterRelSymbol.Range.OffsetStart = Range.startOffset;
-        DefRangeRegisterRelSymbol.Range.Range =
-            Range.endOffset - Range.startOffset;
-        DefRangeRegisterRelSymbol.Range.ISectStart = 0;
-        DefRangeRegisterRelSymbol.Hdr.Register = CVReg;
-        DefRangeRegisterRelSymbol.Hdr.Flags = 0;
-        DefRangeRegisterRelSymbol.Hdr.BasePointerOffset =
-            Range.loc.vlStk.vlsOffset;
-
-        unsigned Length = sizeof(DefRangeRegisterRelSymbol.Hdr);
-        Streamer->emitBytes(
-            StringRef((char *)&DefRangeRegisterRelSymbol.Hdr, Length));
-        EmitVarDefRange(Fn, DefRangeRegisterRelSymbol.Range);
-        break;
-      }
-
-      case ICorDebugInfo::VLT_REG_BYREF:
-      case ICorDebugInfo::VLT_STK_BYREF:
-      case ICorDebugInfo::VLT_REG_REG:
-      case ICorDebugInfo::VLT_REG_STK:
-      case ICorDebugInfo::VLT_STK_REG:
-      case ICorDebugInfo::VLT_STK2:
-      case ICorDebugInfo::VLT_FPSTK:
-      case ICorDebugInfo::VLT_FIXED_VA:
-        // TODO: for optimized debugging
-        break;
-
-      default:
-        assert(false && "Unknown varloc type!");
-        break;
-      }
-    }
-  }
-}
-
-void ObjectWriter::EmitCVDebugFunctionInfo(const char *FunctionName,
-                                           int FunctionSize) {
-  assert(ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF);
-
-  // Mark the end of function.
-  MCSymbol *FnEnd = OutContext->createTempSymbol();
-  Streamer->emitLabel(FnEnd);
-
-  MCSection *Section = ObjFileInfo->getCOFFDebugSymbolsSection();
-  Streamer->SwitchSection(Section);
-  // Emit debug section magic before the first entry.
-  if (FuncId == 1) {
-    Streamer->emitIntValue(COFF::DEBUG_SECTION_MAGIC, 4);
-  }
-  MCSymbol *Fn = OutContext->getOrCreateSymbol(Twine(FunctionName));
-
-  // Emit a symbol subsection, required by VS2012+ to find function boundaries.
-  MCSymbol *SymbolsBegin = OutContext->createTempSymbol(),
-           *SymbolsEnd = OutContext->createTempSymbol();
-  Streamer->emitIntValue(unsigned(DebugSubsectionKind::Symbols), 4);
-  EmitLabelDiff(SymbolsBegin, SymbolsEnd);
-  Streamer->emitLabel(SymbolsBegin);
-  {
-    ProcSym ProcSymbol(SymbolRecordKind::GlobalProcIdSym);
-    ProcSymbol.CodeSize = FunctionSize;
-    ProcSymbol.DbgEnd = FunctionSize;
-
-    unsigned FunctionNameLength = strlen(FunctionName) + 1;
-    unsigned HeaderSize =
-        sizeof(ProcSymbol.Parent) + sizeof(ProcSymbol.End) +
-        sizeof(ProcSymbol.Next) + sizeof(ProcSymbol.CodeSize) +
-        sizeof(ProcSymbol.DbgStart) + sizeof(ProcSymbol.DbgEnd) +
-        sizeof(ProcSymbol.FunctionType);
-    unsigned SymbolSize = HeaderSize + 4 + 2 + 1 + FunctionNameLength;
-    EmitSymRecord(SymbolSize, SymbolRecordKind::GlobalProcIdSym);
-
-    Streamer->emitBytes(StringRef((char *)&ProcSymbol.Parent, HeaderSize));
-    // Emit relocation
-    Streamer->EmitCOFFSecRel32(Fn, 0);
-    Streamer->EmitCOFFSectionIndex(Fn);
-
-    // Emit flags
-    Streamer->emitIntValue(0, 1);
-
-    // Emit the function display name as a null-terminated string.
-
-    Streamer->emitBytes(StringRef(FunctionName, FunctionNameLength));
-
-    // Emit local var info
-    int NumVarInfos = DebugVarInfos.size();
-    if (NumVarInfos > 0) {
-      EmitCVDebugVarInfo(Fn, &DebugVarInfos[0], NumVarInfos);
-      DebugVarInfos.clear();
-    }
-
-    // We're done with this function.
-    EmitSymRecord(0, SymbolRecordKind::ProcEnd);
-  }
-
-  Streamer->emitLabel(SymbolsEnd);
-
-  // Every subsection must be aligned to a 4-byte boundary.
-  Streamer->emitValueToAlignment(4);
-
-  // We have an assembler directive that takes care of the whole line table.
-  // We also increase function id for the next function.
-  Streamer->emitCVLinetableDirective(FuncId++, Fn, FnEnd);
-}
-
-void ObjectWriter::EmitDwarfFunctionInfo(const char *FunctionName,
-                                         int FunctionSize,
-                                         unsigned MethodTypeIndex) {
-  if (FuncId == 1) {
-    DwarfGenerator->EmitCompileUnit();
-  }
-
-  DwarfGenerator->EmitSubprogramInfo(FunctionName, FunctionSize,
-      MethodTypeIndex, DebugVarInfos, DebugEHClauseInfos);
-
-  DebugVarInfos.clear();
-  DebugEHClauseInfos.clear();
-
-  FuncId++;
-}
-
-void ObjectWriter::EmitDebugFileInfo(int FileId, const char *FileName) {
-  assert(FileId > 0 && "FileId should be greater than 0.");
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF) {
-    // TODO: we could pipe through the checksum and hash algorithm from the managed PDB
-    ArrayRef<uint8_t> ChecksumAsBytes;
-    Streamer->EmitCVFileDirective(FileId, FileName, ChecksumAsBytes, 0);
-  } else {
-    Streamer->emitDwarfFileDirective(FileId, "", FileName);
-  }
-}
-
-void ObjectWriter::EmitDebugFunctionInfo(const char *FunctionName,
-                                         int FunctionSize,
-                                         unsigned MethodTypeIndex) {
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF) {
-    Streamer->EmitCVFuncIdDirective(FuncId);
-    EmitCVDebugFunctionInfo(FunctionName, FunctionSize);
-  } else {
-    if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsELF) {
-      MCSymbol *Sym = OutContext->getOrCreateSymbol(Twine(FunctionName));
-      Streamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
-      Streamer->emitELFSize(Sym,
-                            MCConstantExpr::create(FunctionSize, *OutContext));
-      EmitDwarfFunctionInfo(FunctionName, FunctionSize, MethodTypeIndex);
-    }
-    // TODO: Should test it for Macho.
-  }
-}
-
-void ObjectWriter::EmitDebugVar(char *Name, int TypeIndex, bool IsParm,
-                                int RangeCount,
-                                const ICorDebugInfo::NativeVarInfo *Ranges) {
-  assert(RangeCount != 0);
-  DebugVarInfo NewVar(Name, TypeIndex, IsParm);
-
-  for (int I = 0; I < RangeCount; I++) {
-    assert(Ranges[0].varNumber == Ranges[I].varNumber);
-    NewVar.Ranges.push_back(Ranges[I]);
-  }
-
-  DebugVarInfos.push_back(NewVar);
-}
-
-void ObjectWriter::EmitDebugEHClause(unsigned TryOffset, unsigned TryLength,
-                                unsigned HandlerOffset, unsigned HandlerLength) {
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsELF) {
-    DebugEHClauseInfos.emplace_back(TryOffset, TryLength, HandlerOffset, HandlerLength);
-  }
-}
-
-void ObjectWriter::EmitDebugLoc(int NativeOffset, int FileId, int LineNumber,
-                                int ColNumber) {
-  assert(FileId > 0 && "FileId should be greater than 0.");
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF) {
-    Streamer->EmitCVFuncIdDirective(FuncId);
-    Streamer->emitCVLocDirective(FuncId, FileId, LineNumber, ColNumber, false,
-                                 true, "", SMLoc());
-  } else {
-    Streamer->emitDwarfLocDirective(FileId, LineNumber, ColNumber, 1, 0, 0, "");
-  }
-}
-
-void ObjectWriter::EmitCVUserDefinedTypesSymbols() {
-  const auto &UDTs = TypeBuilder->GetUDTs();
-  if (UDTs.empty()) {
-    return;
-  }
-  MCSection *Section = ObjFileInfo->getCOFFDebugSymbolsSection();
-  Streamer->SwitchSection(Section);
-
-  MCSymbol *SymbolsBegin = OutContext->createTempSymbol(),
-           *SymbolsEnd = OutContext->createTempSymbol();
-  Streamer->emitIntValue(unsigned(DebugSubsectionKind::Symbols), 4);
-  EmitLabelDiff(SymbolsBegin, SymbolsEnd);
-  Streamer->emitLabel(SymbolsBegin);
-
-  for (const std::pair<std::string, uint32_t> &UDT : UDTs) {
-    unsigned NameLength = UDT.first.length() + 1;
-    unsigned RecordLength = 2 + 4 + NameLength;
-    Streamer->emitIntValue(RecordLength, 2);
-    Streamer->emitIntValue(unsigned(SymbolKind::S_UDT), 2);
-    Streamer->emitIntValue(UDT.second, 4);
-    Streamer->emitBytes(StringRef(UDT.first.c_str(), NameLength));
-  }
-  Streamer->emitLabel(SymbolsEnd);
-  Streamer->emitValueToAlignment(4);
-}
-
-void ObjectWriter::EmitDebugModuleInfo() {
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF) {
-    TypeBuilder->EmitTypeInformation(ObjFileInfo->getCOFFDebugTypesSection());
-    EmitCVUserDefinedTypesSymbols();
-  }
-
-  // Ensure ending all sections.
-  for (auto Section : Sections) {
-    Streamer->endSection(Section);
-  }
-
-  if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsCOFF) {
-    MCSection *Section = ObjFileInfo->getCOFFDebugSymbolsSection();
-    Streamer->SwitchSection(Section);
-    Streamer->emitCVFileChecksumsDirective();
-    Streamer->emitCVStringTableDirective();
-  } else if (ObjFileInfo->getObjectFileType() == ObjFileInfo->IsELF) {
-    DwarfGenerator->EmitAbbrev();
-    DwarfGenerator->EmitAranges();
-    DwarfGenerator->Finish();
-  } else {
-    OutContext->setGenDwarfForAssembly(true);
-  }
-}
-
-unsigned
-ObjectWriter::GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor,
-                               const EnumRecordTypeDescriptor *TypeRecords) {
-  return TypeBuilder->GetEnumTypeIndex(TypeDescriptor, TypeRecords);
-}
-
-unsigned
-ObjectWriter::GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) {
-  unsigned res = TypeBuilder->GetClassTypeIndex(ClassDescriptor);
-  return res;
-}
-
-unsigned ObjectWriter::GetCompleteClassTypeIndex(
-    const ClassTypeDescriptor &ClassDescriptor,
-    const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-    const DataFieldDescriptor *FieldsDescriptors,
-    const StaticDataFieldDescriptor *StaticsDescriptors) {
-  unsigned res = TypeBuilder->GetCompleteClassTypeIndex(ClassDescriptor,
-      ClassFieldsDescriptor, FieldsDescriptors, StaticsDescriptors);
-  return res;
-}
-
-unsigned
-ObjectWriter::GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor,
-                                const ArrayTypeDescriptor &ArrayDescriptor) {
-  return TypeBuilder->GetArrayTypeIndex(ClassDescriptor, ArrayDescriptor);
-}
-
-unsigned 
-ObjectWriter::GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) {
-    return TypeBuilder->GetPointerTypeIndex(PointerDescriptor);
-}
-
-unsigned 
-ObjectWriter::GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-                                         uint32_t const *const ArgumentTypes) {
-    return TypeBuilder->GetMemberFunctionTypeIndex(MemberDescriptor, ArgumentTypes);
-}
-
-unsigned 
-ObjectWriter::GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) {
-    return TypeBuilder->GetMemberFunctionId(MemberIdDescriptor);
-}
-
-unsigned
-ObjectWriter::GetPrimitiveTypeIndex(int Type) {
-  return TypeBuilder->GetPrimitiveTypeIndex(static_cast<PrimitiveTypeFlags>(Type));
-}
-
-void
-ObjectWriter::EmitARMFnStart() {
-  MCTargetStreamer &TS = *(Streamer->getTargetStreamer());
-  ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
-
-  ATS.emitFnStart();
-}
-
-void ObjectWriter::EmitARMFnEnd() {
-
-  if (!CFIsPerOffset.empty())
-  {
-    EmitARMExIdxPerOffset();
-  }
-
-  MCTargetStreamer &TS = *(Streamer->getTargetStreamer());
-  ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
-
-  ATS.emitFnEnd();
-}
-
-void ObjectWriter::EmitARMExIdxLsda(const char *LsdaBlobSymbolName)
-{
-  MCTargetStreamer &TS = *(Streamer->getTargetStreamer());
-  ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
-
-  MCSymbol *T = OutContext->getOrCreateSymbol(LsdaBlobSymbolName);
-  Assembler->registerSymbol(*T);
-
-  ATS.emitLsda(T);
-}
-
-void ObjectWriter::EmitARMExIdxPerOffset()
-{
-  MCTargetStreamer &TS = *(Streamer->getTargetStreamer());
-  ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
-  const MCRegisterInfo *MRI = OutContext->getRegisterInfo();
-
-  SmallVector<unsigned, 32> RegSet;
-  bool IsVector = false;
-
-  // LLVM reverses opcodes that are fed to ARMTargetStreamer, so we do the same,
-  // but per code offset. Opcodes with different code offsets are already given in
-  // the correct order.
-  for (int i = CFIsPerOffset.size() - 1; i >= 0; --i)
-  {
-    unsigned char opCode = CFIsPerOffset[i].CfiOpCode;
-    short Reg = CFIsPerOffset[i].DwarfReg;
-
-    if (RegSet.empty() && opCode == CFI_REL_OFFSET)
-    {
-      IsVector = Reg >= 16;
-    }
-    else if (!RegSet.empty() && opCode != CFI_REL_OFFSET)
-    {
-      ATS.emitRegSave(RegSet, IsVector);
-      RegSet.clear();
-    }
-
-    switch (opCode)
-    {
-    case CFI_REL_OFFSET:
-      assert(IsVector == (Reg >= 16) && "Unexpected Register Type");
-      RegSet.push_back(MRI->getLLVMRegNum(Reg, true).getValue());
-      break;
-    case CFI_ADJUST_CFA_OFFSET:
-      assert(Reg == DWARF_REG_ILLEGAL &&
-          "Unexpected Register Value for OpAdjustCfaOffset");
-      ATS.emitPad(CFIsPerOffset[i].Offset);
-      break;
-    case CFI_DEF_CFA_REGISTER:
-      ATS.emitMovSP(MRI->getLLVMRegNum(Reg, true).getValue());
-      break;
-    default:
-      assert(false && "Unrecognized CFI");
-      break;
-    }
-  }
-
-  // if we have some registers left over, emit them
-  if (!RegSet.empty())
-  {
-      ATS.emitRegSave(RegSet, IsVector);
-  }
-
-  CFIsPerOffset.clear();
-}
-
-void ObjectWriter::EmitARMExIdxCode(int Offset, const char *Blob)
-{
-  const CFI_CODE *CfiCode = (const CFI_CODE *)Blob;
-
-  if (!CFIsPerOffset.empty() && CFIsPerOffset[0].CodeOffset != CfiCode->CodeOffset)
-  {
-    EmitARMExIdxPerOffset();
-  }
-  
-  CFIsPerOffset.push_back(*CfiCode);
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/objwriter.exports b/src/coreclr/tools/aot/ObjWriter/objwriter.exports
deleted file mode 100644 (file)
index 4065510..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-InitObjWriter
-FinishObjWriter
-SwitchSection
-SetCodeSectionAttribute
-EmitAlignment
-EmitBlob
-EmitIntValue
-EmitSymbolDef
-EmitSymbolRef
-EmitWinFrameInfo
-EmitCFIStart
-EmitCFIEnd
-EmitCFILsda
-EmitCFICode
-EmitDebugFileInfo
-EmitDebugFunctionInfo
-EmitDebugVar
-EmitDebugEHClause
-EmitDebugLoc
-EmitDebugModuleInfo
-GetEnumTypeIndex
-GetClassTypeIndex
-GetCompleteClassTypeIndex
-GetArrayTypeIndex
-GetPointerTypeIndex
-GetMemberFunctionTypeIndex
-GetMemberFunctionIdTypeIndex
-GetPrimitiveTypeIndex
-EmitARMFnStart
-EmitARMFnEnd
-EmitARMExIdxLsda
-EmitARMExIdxCode
diff --git a/src/coreclr/tools/aot/ObjWriter/objwriter.h b/src/coreclr/tools/aot/ObjWriter/objwriter.h
deleted file mode 100644 (file)
index 4840cf7..0000000
+++ /dev/null
@@ -1,397 +0,0 @@
-//===---- objwriter.h ------------------------------------------*- C++ -*-===//
-//
-// object writer
-//
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/MC/MCInstrInfo.h"
-#include "llvm/MC/MCObjectFileInfo.h"
-#include "llvm/Target/TargetOptions.h"
-#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
-
-#include "cfi.h"
-#include "jitDebugInfo.h"
-#include "debugInfo/dwarf/dwarfGen.h"
-
-#include <set>
-#include <string>
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-#ifdef _WIN32
-#define DLL_EXPORT extern "C" __declspec(dllexport)
-#else
-#define DLL_EXPORT extern "C" __attribute((visibility("default")))
-#endif
-
-// ***
-// Define default call conventions
-// ***
-#if defined(HOST_X86) && !defined(HOST_UNIX)
-#define STDMETHODCALLTYPE  __stdcall
-#else
-#define STDMETHODCALLTYPE
-#endif //  defined(HOST_X86) && !defined(HOST_UNIX)
-
-typedef uint16_t CVRegNum;
-
-enum CustomSectionAttributes : int32_t {
-  CustomSectionAttributes_ReadOnly = 0x0000,
-  CustomSectionAttributes_Writeable = 0x0001,
-  CustomSectionAttributes_Executable = 0x0002,
-  CustomSectionAttributes_MachO_Init_Func_Pointers = 0x0100,
-};
-
-enum class RelocType {
-  IMAGE_REL_BASED_ABSOLUTE = 0x00,
-  IMAGE_REL_BASED_HIGHLOW = 0x03,
-  IMAGE_REL_BASED_THUMB_MOV32 = 0x07,
-  IMAGE_REL_BASED_DIR64 = 0x0A,
-  IMAGE_REL_BASED_REL32 = 0x10,
-  IMAGE_REL_BASED_THUMB_BRANCH24 = 0x13,
-  IMAGE_REL_BASED_ARM64_BRANCH26 = 0x15,
-  IMAGE_REL_BASED_RELPTR32 = 0x7C,
-  IMAGE_REL_BASED_ARM64_PAGEBASE_REL21 = 0x81,
-  IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A = 0x82,
-};
-
-enum class SymbolRefFlags
-{
-  SymbolRefFlags_AddressTakenFunction = 0x0001,
-};
-
-class ObjectWriter {
-public:
-  bool Init(StringRef FunctionName, const char* tripleName = nullptr);
-  void Finish();
-
-  void SwitchSection(const char *SectionName,
-                     CustomSectionAttributes attributes,
-                     const char *ComdatName);
-  void SetCodeSectionAttribute(const char *SectionName,
-                               CustomSectionAttributes attributes,
-                               const char *ComdatName);
-
-  void EmitAlignment(int ByteAlignment);
-  void EmitBlob(int BlobSize, const char *Blob);
-  void EmitIntValue(uint64_t Value, unsigned Size);
-  void EmitSymbolDef(const char *SymbolName, bool global);
-  void EmitWinFrameInfo(const char *FunctionName, int StartOffset,
-                        int EndOffset, const char *BlobSymbolName);
-  int EmitSymbolRef(const char *SymbolName, RelocType RelocType, int Delta, SymbolRefFlags Flags);
-
-  void EmitDebugFileInfo(int FileId, const char *FileName);
-  void EmitDebugFunctionInfo(const char *FunctionName, int FunctionSize, unsigned MethodTypeIndex);
-  void EmitDebugVar(char *Name, int TypeIndex, bool IsParm, int RangeCount,
-                    const ICorDebugInfo::NativeVarInfo *Ranges);
-  void EmitDebugLoc(int NativeOffset, int FileId, int LineNumber,
-                    int ColNumber);
-  void EmitDebugEHClause(unsigned TryOffset, unsigned TryLength,
-                         unsigned HandlerOffset, unsigned HandlerLength);
-  void EmitDebugModuleInfo();
-
-  void EmitCFIStart(int Offset);
-  void EmitCFIEnd(int Offset);
-  void EmitCFILsda(const char *LsdaBlobSymbolName);
-  void EmitCFICode(int Offset, const char *Blob);
-
-  unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor,
-                            const EnumRecordTypeDescriptor *TypeRecords);
-  unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor);
-  unsigned GetCompleteClassTypeIndex(
-      const ClassTypeDescriptor &ClassDescriptor,
-      const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
-      const DataFieldDescriptor *FieldsDescriptors,
-      const StaticDataFieldDescriptor *StaticsDescriptors);
-
-  unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor,
-                             const ArrayTypeDescriptor &ArrayDescriptor);
-
-  unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor);
-
-  unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
-                                      uint32_t const *const ArgumentTypes);
-
-  unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor);
-
-  unsigned GetPrimitiveTypeIndex(int Type);
-
-  void EmitARMFnStart();
-  void EmitARMFnEnd();
-  void EmitARMExIdxCode(int Offset, const char *Blob);
-  void EmitARMExIdxLsda(const char *Blob);
-
-private:
-  void EmitLabelDiff(const MCSymbol *From, const MCSymbol *To,
-                     unsigned int Size = 4);
-  void EmitSymRecord(int Size, SymbolRecordKind SymbolKind);
-  void EmitCOFFSecRel32Value(MCExpr const *Value);
-
-  void EmitVarDefRange(const MCSymbol *Fn, const LocalVariableAddrRange &Range);
-
-  CVRegNum GetCVRegNum(unsigned RegNum);
-  void EmitCVDebugVarInfo(const MCSymbol *Fn, const DebugVarInfo LocInfos[],
-                          int NumVarInfos);
-  void EmitCVDebugFunctionInfo(const char *FunctionName, int FunctionSize);
-
-  void EmitDwarfFunctionInfo(const char *FunctionName, int FunctionSize, unsigned MethodTypeIndex);
-
-  const MCSymbolRefExpr *GetSymbolRefExpr(
-      const char *SymbolName,
-      MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None);
-
-  MCSection *GetSection(const char *SectionName,
-                        CustomSectionAttributes attributes,
-                        const char *ComdatName);
-
-  MCSection *GetSpecificSection(const char *SectionName,
-                                CustomSectionAttributes attributes,
-                                const char *ComdatName);
-
-  void EmitCVUserDefinedTypesSymbols();
-
-  void InitTripleName(const char* tripleName = nullptr);
-  Triple GetTriple();
-  unsigned GetDFSize();
-  void EmitRelocDirective(const int Offset, StringRef Name, const MCExpr *Expr);
-  const MCExpr *GenTargetExpr(const MCSymbol* Symbol,
-                              MCSymbolRefExpr::VariantKind Kind, int Delta,
-                              bool IsPCRel = false, int Size = 0);
-  void EmitARMExIdxPerOffset();
-
-
-private:
-  std::unique_ptr<MCRegisterInfo> RegisterInfo;
-  std::unique_ptr<MCAsmInfo> AsmInfo;
-  std::unique_ptr<MCObjectFileInfo> ObjFileInfo;
-  std::unique_ptr<MCContext> OutContext;
-  MCAsmBackend *AsmBackend; // Owned by MCStreamer
-  std::unique_ptr<MCInstrInfo> InstrInfo;
-  std::unique_ptr<MCSubtargetInfo> SubtargetInfo;
-  MCCodeEmitter *CodeEmitter; // Owned by MCStreamer
-  MCAssembler *Assembler; // Owned by MCStreamer
-  std::unique_ptr<DwarfGen> DwarfGenerator;
-
-  std::unique_ptr<raw_fd_ostream> OS;
-  MCTargetOptions TargetMOptions;
-  bool FrameOpened;
-  std::vector<DebugVarInfo> DebugVarInfos;
-  std::vector<DebugEHClauseInfo> DebugEHClauseInfos;
-  DenseSet<MCSymbol *> AddressTakenFunctions;
-
-  std::set<MCSection *> Sections;
-  int FuncId;
-
-  std::unique_ptr<UserDefinedTypesBuilder> TypeBuilder;
-
-  std::string TripleName;
-
-  MCObjectStreamer *Streamer; // Owned by AsmPrinter
-
-  SmallVector<CFI_CODE, 32> CFIsPerOffset;
-};
-
-// When object writer is created/initialized successfully, it is returned.
-// Or null object is returned. Client should check this.
-DLL_EXPORT STDMETHODCALLTYPE ObjectWriter *InitObjWriter(const char *ObjectFilePath, const char* TripleName = nullptr) {
-  ObjectWriter *OW = new ObjectWriter();
-  if (OW->Init(ObjectFilePath, TripleName)) {
-    return OW;
-  }
-  delete OW;
-  return nullptr;
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void FinishObjWriter(ObjectWriter *OW) {
-  assert(OW && "ObjWriter is null");
-  OW->Finish();
-  delete OW;
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void SwitchSection(ObjectWriter *OW, const char *SectionName,
-                              CustomSectionAttributes attributes,
-                              const char *ComdatName) {
-  assert(OW && "ObjWriter is null");
-  OW->SwitchSection(SectionName, attributes, ComdatName);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void SetCodeSectionAttribute(ObjectWriter *OW,
-                                        const char *SectionName,
-                                        CustomSectionAttributes attributes,
-                                        const char *ComdatName) {
-  assert(OW && "ObjWriter is null");
-  OW->SetCodeSectionAttribute(SectionName, attributes, ComdatName);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitAlignment(ObjectWriter *OW, int ByteAlignment) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitAlignment(ByteAlignment);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitBlob(ObjectWriter *OW, int BlobSize, const char *Blob) {
-  assert(OW && "ObjWriter null");
-  OW->EmitBlob(BlobSize, Blob);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitIntValue(ObjectWriter *OW, uint64_t Value, unsigned Size) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitIntValue(Value, Size);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitSymbolDef(ObjectWriter *OW, const char *SymbolName, bool global) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitSymbolDef(SymbolName, global);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE int EmitSymbolRef(ObjectWriter *OW, const char *SymbolName,
-                             RelocType RelocType, int Delta, SymbolRefFlags Flags) {
-  assert(OW && "ObjWriter is null");
-  return OW->EmitSymbolRef(SymbolName, RelocType, Delta, Flags);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitWinFrameInfo(ObjectWriter *OW, const char *FunctionName,
-                                 int StartOffset, int EndOffset,
-                                 const char *BlobSymbolName) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitWinFrameInfo(FunctionName, StartOffset, EndOffset, BlobSymbolName);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitCFIStart(ObjectWriter *OW, int Offset) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitCFIStart(Offset);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitCFIEnd(ObjectWriter *OW, int Offset) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitCFIEnd(Offset);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitCFILsda(ObjectWriter *OW, const char *LsdaBlobSymbolName) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitCFILsda(LsdaBlobSymbolName);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitCFICode(ObjectWriter *OW, int Offset, const char *Blob) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitCFICode(Offset, Blob);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitDebugFileInfo(ObjectWriter *OW, int FileId,
-                                  const char *FileName) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitDebugFileInfo(FileId, FileName);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitDebugFunctionInfo(ObjectWriter *OW,
-                                      const char *FunctionName,
-                                      int FunctionSize,
-                                      unsigned MethodTypeIndex) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitDebugFunctionInfo(FunctionName, FunctionSize, MethodTypeIndex);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitDebugVar(ObjectWriter *OW, char *Name, int TypeIndex,
-                             bool IsParam, int RangeCount,
-                             ICorDebugInfo::NativeVarInfo *Ranges) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitDebugVar(Name, TypeIndex, IsParam, RangeCount, Ranges);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitDebugEHClause(ObjectWriter *OW, unsigned TryOffset,
-                                  unsigned TryLength, unsigned HandlerOffset,
-                                  unsigned HandlerLength) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitDebugEHClause(TryOffset, TryLength, HandlerOffset, HandlerLength);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitDebugLoc(ObjectWriter *OW, int NativeOffset, int FileId,
-                             int LineNumber, int ColNumber) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitDebugLoc(NativeOffset, FileId, LineNumber, ColNumber);
-}
-
-// This should be invoked at the end of module emission to finalize
-// debug module info.
-DLL_EXPORT STDMETHODCALLTYPE void EmitDebugModuleInfo(ObjectWriter *OW) {
-  assert(OW && "ObjWriter is null");
-  OW->EmitDebugModuleInfo();
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetEnumTypeIndex(ObjectWriter *OW,
-                                     EnumTypeDescriptor TypeDescriptor,
-                                     EnumRecordTypeDescriptor *TypeRecords) {
-  assert(OW && "ObjWriter is null");
-  return OW->GetEnumTypeIndex(TypeDescriptor, TypeRecords);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetClassTypeIndex(ObjectWriter *OW,
-                                      ClassTypeDescriptor ClassDescriptor) {
-  assert(OW && "ObjWriter is null");
-  return OW->GetClassTypeIndex(ClassDescriptor);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned
-GetCompleteClassTypeIndex(ObjectWriter *OW, ClassTypeDescriptor ClassDescriptor,
-                          ClassFieldsTypeDescriptior ClassFieldsDescriptor,
-                          DataFieldDescriptor *FieldsDescriptors,
-                          StaticDataFieldDescriptor *StaticsDescriptors) {
-  assert(OW && "ObjWriter is null");
-  return OW->GetCompleteClassTypeIndex(ClassDescriptor, ClassFieldsDescriptor,
-                                       FieldsDescriptors, StaticsDescriptors);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetArrayTypeIndex(ObjectWriter *OW,
-                                      ClassTypeDescriptor ClassDescriptor,
-                                      ArrayTypeDescriptor ArrayDescriptor) {
-  assert(OW && "ObjWriter is null");
-  return OW->GetArrayTypeIndex(ClassDescriptor, ArrayDescriptor);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetPointerTypeIndex(ObjectWriter *OW,
-    PointerTypeDescriptor PointerDescriptor) {
-    assert(OW && "ObjWriter is null");
-    return OW->GetPointerTypeIndex(PointerDescriptor);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetMemberFunctionTypeIndex(ObjectWriter *OW,
-    MemberFunctionTypeDescriptor MemberDescriptor,
-    uint32_t *ArgumentTypes) {
-    assert(OW && "ObjWriter is null");
-    return OW->GetMemberFunctionTypeIndex(MemberDescriptor, ArgumentTypes);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetMemberFunctionIdTypeIndex(ObjectWriter *OW,
-    MemberFunctionIdTypeDescriptor MemberIdDescriptor) {
-    assert(OW && "ObjWriter is null");
-    return OW->GetMemberFunctionId(MemberIdDescriptor);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE unsigned GetPrimitiveTypeIndex(ObjectWriter *OW, int Type) {
-    assert(OW && "ObjWriter is null");
-    return OW->GetPrimitiveTypeIndex(Type);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitARMFnStart(ObjectWriter *OW) {
-    assert(OW && "ObjWriter is null");
-    return OW->EmitARMFnStart();
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitARMFnEnd(ObjectWriter *OW) {
-  assert(OW && "ObjWriter is null");
-  return OW->EmitARMFnEnd();
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitARMExIdxLsda(ObjectWriter *OW, const char *Blob) {
-  assert(OW && "ObjWriter is null");
-  return OW->EmitARMExIdxLsda(Blob);
-}
-
-DLL_EXPORT STDMETHODCALLTYPE void EmitARMExIdxCode(ObjectWriter *OW, int Offset, const char *Blob) {
-  assert(OW && "ObjWriter is null");
-  return OW->EmitARMExIdxCode(Offset, Blob);
-}
diff --git a/src/coreclr/tools/aot/ObjWriter/objwriter.proj b/src/coreclr/tools/aot/ObjWriter/objwriter.proj
deleted file mode 100644 (file)
index 0cf0d56..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<Project>
-  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
-
-  <PropertyGroup>
-    <BuildScriptName Condition="'$(TargetOS)' == 'windows'">build.cmd</BuildScriptName>
-    <BuildScriptName Condition="'$(TargetOS)' != 'windows'">build.sh</BuildScriptName>
-
-    <ObjWriterBuildType>$(Configuration)</ObjWriterBuildType>
-    <ObjWriterBuildType Condition="'$(ObjWriterBuildType)' == 'Checked'">Debug</ObjWriterBuildType>
-
-    <BuildArguments>"$(ArtifactsDir)" "$(RepoRoot)"</BuildArguments>
-    <BuildArguments>$(BuildArguments) $(BuildArchitecture) $(TargetArchitecture)</BuildArguments>
-    <BuildArguments>$(BuildArguments) $(ObjWriterBuildType) $(Compiler)</BuildArguments>
-  </PropertyGroup>
-
-  <Target Name="Build">
-    <!-- Use IgnoreStandardErrorWarningFormat because Arcade sets WarnAsError and there are multiple warnings in the LLVM build -->
-    <Exec Command="&quot;$(MSBuildThisFileDirectory)$(BuildScriptName)&quot; $(BuildArguments)"
-          IgnoreStandardErrorWarningFormat="true" />
-  </Target>
-</Project>
diff --git a/src/coreclr/tools/aot/ObjWriter/toolchain.cmake b/src/coreclr/tools/aot/ObjWriter/toolchain.cmake
deleted file mode 100644 (file)
index 83f0484..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-if (WIN32)
-  # Use static CRT
-  set(LLVM_USE_CRT_DEBUG MTd)
-  set(LLVM_USE_CRT_RELEASE MT)
-  set(LLVM_USE_CRT_MINSIZEREL MT)
-  set(LLVM_USE_CRT_RELWITHDEBINFO MT)
-
-  # Enable debug information for Release builds
-  set(CMAKE_CXX_FLAGS_RELEASE_INIT /Zi)
-  set(CMAKE_C_FLAGS_RELEASE_INIT /Zi)
-  set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT "/debug /OPT:REF /OPT:ICF")
-endif()