-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
4
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
//===-- 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/RISCVMCExpr.h" | ||
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. RISCVMCExpr.h has been deleted. This file doesn't need the header. |
||
#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/MCFragment.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"); | ||
} | ||
|
||
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
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 | ||
; 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.