Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Merge ObjWriter into dotnet/main and update to LLVM 14 API #287

Merged
merged 45 commits into from
Feb 7, 2023

Conversation

filipnavara
Copy link
Member

No description provided.

MichalStrehovsky and others added 17 commits November 16, 2022 10:50
* Taken from https://github.com/dotnet/runtime/tree/7ab969c84ef05ba948c0075392716ce335b47744/src/coreclr/tools/aot/ObjWriter.
* Updated README.md
* Updated CMakeLists.txt to remove reference to CORECLR_INCLUDE_DIR.
* Added cordebuginfo.h, cvconst.h, cfi.h from coreclr/inc at the above commit.
Do this unconditionally because there's no scenario where we would need executable stack for managed code.
This caught my attention as I was looking at the ObjWriter. LLVM no longer emits a `LC_VERSION_MIN_MACOSX` load command unless we explicitly set a version. I don't see a difference in `llvm-objdump -macho -x foo.o` with/without these lines (I didn't bother myself to boot into macOS to run `otool`).
…s `FileCheck` and `llvm-mca` (dotnet#256)

https://github.com/dotnet/runtime is wanting to start writing assembly (x64/ARM64) verification tests. Instead of building our own tool to support writing those kinds of tests, we want to leverage LLVM's `FileCheck`.

We also want to include `llvm-mca` at the request of @EgorBo

This PR creates a new NuGet package for `dotnet/runtime` to consume which we named `Microsoft.NETCore.Runtime.JIT.Tools`. So far, this package only includes LLVM's `FileCheck` and `llvm-mca` tools.
We support `.bss` but not custom sections that are bss-like. This adds such support.
If we ended up with nothing in the text section, this line would error LLVM out in:

https://github.com/dotnet/llvm-project/blob/3db8d68195c17386557f1a258312bbae4051dc05/llvm/lib/MC/ELFObjectWriter.cpp#L1458-L1459

Because we generate a reference to the empty text section in the `aranges` section.

I double checked and debugging on Linux still works fine without this. `SetCodeSectionAttribute` is an objwriter API and we have access to it from the managed side. We should be calling it from there if it's needed for something that I didn't realize (we do call it from the managed side for the `.managed` section, but that one actually has debug information generated, unlike `.text`).
The DWARF specification states that the form of an exprloc consists
of an unsigned LEB128 length value, followed by the encoded location bytes
of the specified length. For some reason we were adding one to the length
value being emitted. This looks incorrect to me. The above calculation for
REG-REG (a variable stored in two registers) correctly calculates the length
of each register type tag, plus the size of the interpolating PIECE tags,
plus the size of notation for each register. The extra byte looks wrong.

I've tested this locally and it appears to resolve dotnet/runtime#77407.

Unfortunately, it also causes llvm-dwarfdump --verify to constantly
complain about missing base addresses. I can't confirm at the moment,
but my suspicion is that this is revealing an existing bug. Even if this
is somehow causing a new bug, I think the resulting symbols with this
change are better than the alternative (no working symbols at all).
@BrianBohe BrianBohe marked this pull request as ready for review January 2, 2023 07:09
@BrianBohe
Copy link
Member

Hi @filipnavara, first of all thanks for your contributions 😁, I am following up this PR because I want to measure how much effort would it take to upgrade llvm's version

@filipnavara
Copy link
Member Author

The effort should not be that big. Not sure if I applied all the recent patches from ObjWriter branch. Fixing the build breaks would likely be relatively easy too (at least by switching to different build machine images). I am more than happy to revive this PR if there's interest.

@BrianBohe
Copy link
Member

at least by switching to different build machine images

@filipnavara Do you mean upgrading linux build image version in the yaml file? I am not able to reproduce locally the error the pipeline is getting

@filipnavara
Copy link
Member Author

Thanks for fixing the compiler references. Now we are back to an error that was occurring previously:

  clang-tblgen: Unknown command line argument '-gen-attrs'.  Try: '/__w/1/s/artifacts/obj/BuildRoot-x64/bin/clang-tblgen --help'
  clang-tblgen: Did you mean '--gen-attr-docs'?

I'll try to reproduce and fix it locally.

eng/azure-pipelines.yml Outdated Show resolved Hide resolved
BrianBohe and others added 2 commits February 2, 2023 20:15
$(ClangVersion) $(ClangPlusVersion) weren't defined for OSX and should be defined for every Linux
@BrianBohe
Copy link
Member

Thanks @filipnavara! Nice work!

@BrianBohe BrianBohe self-requested a review February 3, 2023 18:47
Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me apart from a few comments. Thank you!

eng/azure-pipelines.yml Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
eng/azure-pipelines.yml Outdated Show resolved Hide resolved
eng/azure-pipelines.yml Outdated Show resolved Hide resolved
llvm/tools/objwriter/cordebuginfo.h Outdated Show resolved Hide resolved
Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@agocke agocke merged commit 7de031a into dotnet:dotnet/main Feb 7, 2023
@agocke
Copy link
Member

agocke commented Feb 7, 2023

@filipnavara Thanks for the contribution!

@filipnavara filipnavara deleted the objwriter/main branch February 7, 2023 18:44
@filipnavara
Copy link
Member Author

Happy to help!

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

Successfully merging this pull request may close these issues.

7 participants