-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[RISCV] Add basic Mach-O triple support. #141682
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
Open
fpetrogalli
wants to merge
16
commits into
llvm:main
Choose a base branch
from
fpetrogalli:basic-macho-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−1
Open
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b411217
[RISCV] Add basic MachO support.
fpetrogalli 57c567c
Assert on nullptr.
fpetrogalli 89eb2b9
Assert on invalid triple/ABI.
fpetrogalli 639dc66
Move computeDataLayout to TargetParser. [NFCI]
fpetrogalli 155e581
Fix the test.
fpetrogalli fde002c
Add assertion on endianness.
fpetrogalli 7b5eae7
Address code formatting issues. [NFC]
fpetrogalli c4a264e
Remove period from assertion. [nfc]
fpetrogalli 061d63f
Eliminate the else-after-return [NFCI]
fpetrogalli b4fccfe
Report fatal error instead of assert on initialized MAI.
fpetrogalli e2088f5
Fix silly bug. [Functional Changes Intended!!!!]
fpetrogalli 941717d
Rename file. [NFC]
fpetrogalli 624b683
Remove function that is not used.
fpetrogalli 5ae6609
Change order of files in CMake configuration. [NFC]
fpetrogalli d208ceb
Ensure local symbols are correctly added to the symbol table.
fpetrogalli d513e1c
Apply clang format [NFC]
fpetrogalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMachObjectWriter.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===-- RISCVMachObjectWriter.cpp - RISC-V Mach Object Writer -------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "MCTargetDesc/RISCVFixupKinds.h" | ||
#include "MCTargetDesc/RISCVMCTargetDesc.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/ADT/Twine.h" | ||
#include "llvm/BinaryFormat/MachO.h" | ||
#include "llvm/MC/MCAsmInfo.h" | ||
#include "llvm/MC/MCAssembler.h" | ||
#include "llvm/MC/MCContext.h" | ||
#include "llvm/MC/MCExpr.h" | ||
#include "llvm/MC/MCFixup.h" | ||
#include "llvm/MC/MCMachObjectWriter.h" | ||
#include "llvm/MC/MCSection.h" | ||
#include "llvm/MC/MCSectionMachO.h" | ||
#include "llvm/MC/MCSymbol.h" | ||
#include "llvm/MC/MCValue.h" | ||
#include "llvm/Support/Casting.h" | ||
#include "llvm/Support/MathExtras.h" | ||
#include <cassert> | ||
#include <cstdint> | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
class RISCVMachObjectWriter : public MCMachObjectTargetWriter { | ||
public: | ||
RISCVMachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype) | ||
: MCMachObjectTargetWriter(false, CPUType, CPUSubtype) {} | ||
|
||
void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, | ||
const MCFragment *Fragment, const MCFixup &Fixup, | ||
MCValue Target, uint64_t &FixedValue) override; | ||
}; | ||
|
||
} // end anonymous namespace | ||
|
||
void RISCVMachObjectWriter::recordRelocation( | ||
MachObjectWriter *Writer, MCAssembler &Asm, const MCFragment *Fragment, | ||
const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) { | ||
llvm_unreachable("unimplemented"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for all the reviews. I am holding the merge of this PR, because I want to create a PR on top of this that implements the relocations. |
||
} | ||
|
||
std::unique_ptr<MCObjectTargetWriter> | ||
llvm::createRISCVMachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype) { | ||
return std::make_unique<RISCVMachObjectWriter>(CPUType, CPUSubtype); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; RUN: llc -mtriple=riscv32-apple-macho %s -o - | FileCheck %s | ||
; RUN: llc -mtriple=riscv32-apple-macho -filetype=obj %s -o %t.o | ||
; RUN: llvm-objdump -D %t.o | FileCheck %s --check-prefix=CHECK-OBJ | ||
|
||
; CHECK-LABEL: _main: | ||
; CHECK: li a0, 0 | ||
; CHECK: ret | ||
|
||
; CHECK-OBJ: li a0, 0 | ||
; CHECK-OBJ: ret | ||
define i32 @main() nounwind { | ||
ret i32 0 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; RUN: llvm-mc -triple riscv32-apple-macho %s -o - | FileCheck %s | ||
fpetrogalli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; RUN: llvm-mc -triple riscv32-apple-macho -filetype=obj %s -o %t.o | ||
; RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefix=CHECK-DIS | ||
; RUN: llvm-nm %t.o | FileCheck %s --check-prefix=CHECK-SYMS | ||
|
||
nop | ||
.half 42 | ||
.word 42 | ||
Lfoo: | ||
lfoo: | ||
foo: | ||
|
||
; CHECK: nop | ||
; CHECK: .half 42 | ||
; CHECK: .word 42 | ||
|
||
; CHECK-DIS: file format mach-o 32-bit risc-v | ||
; CHECK-DIS: Disassembly of section __TEXT,__text: | ||
; CHECK-DIS: nop | ||
; CHECK-DIS: 002a <unknown> | ||
; CHECK-DIS: 002a <unknown> | ||
; CHECK-DIS: 0000 <unknown> | ||
|
||
; CHECK-SYMS-NOT: Lfoo | ||
; CHECK-SYMS: foo | ||
; CHECK-SYMS: lfoo |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.