-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Generate an .sframe section with a skeleton header #151223
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b764e2
Generate an .sframe section with a skeleton header
Sterling-Augustine 0d6691c
Fix formatting
Sterling-Augustine 8053032
Address comments:
Sterling-Augustine bd26100
Address comments.
Sterling-Augustine bb33f3c
Address comments
Sterling-Augustine 4b5cdcd
Merge branch 'main' into sf_header
Sterling-Augustine 4e4cc0f
Remove currently unused includes
Sterling-Augustine 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===- MCSFrame.h - Machine Code SFrame support -----------------*- C++ -*-===// | ||
Sterling-Augustine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains the declaration of MCSFrameEmitter to support emitting | ||
// sframe unwinding info from .cfi_* directives. It relies on FDEs and CIEs | ||
// created for Dwarf frame info, but emits that info in a different format. | ||
// | ||
// See https://sourceware.org/binutils/docs-2.41/sframe-spec.html | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_MC_MCSFRAME_H | ||
#define LLVM_MC_MCSFRAME_H | ||
|
||
#include <cstdint> | ||
|
||
#include "llvm/ADT/SmallVector.h" | ||
Sterling-Augustine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace llvm { | ||
|
||
class MCObjectStreamer; | ||
|
||
class MCSFrameEmitter { | ||
public: | ||
// | ||
// Emits the sframe section. | ||
// | ||
Sterling-Augustine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static void Emit(MCObjectStreamer &streamer); | ||
}; | ||
|
||
} // end namespace llvm | ||
#endif // LLVM_MC_MCSFRAME_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//===- lib/MC/MCSFrame.cpp - MCSFrame implementation ----------------------===// | ||
// | ||
// 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 "llvm/MC/MCSFrame.h" | ||
#include "llvm/BinaryFormat/SFrame.h" | ||
#include "llvm/MC/MCContext.h" | ||
#include "llvm/MC/MCObjectFileInfo.h" | ||
#include "llvm/MC/MCObjectStreamer.h" | ||
#include "llvm/MC/MCSection.h" | ||
#include "llvm/MC/MCSymbol.h" | ||
#include "llvm/Support/EndianStream.h" | ||
|
||
using namespace llvm; | ||
using namespace sframe; | ||
|
||
namespace { | ||
|
||
// Emitting these field-by-field, instead of constructing the actual structures | ||
// lets Streamer do target endian-fixups for free. | ||
|
||
class SFrameEmitterImpl { | ||
MCObjectStreamer &Streamer; | ||
ABI SFrameABI; | ||
MCSymbol *FDESubSectionStart; | ||
MCSymbol *FRESubSectionStart; | ||
MCSymbol *FRESubSectionEnd; | ||
|
||
public: | ||
SFrameEmitterImpl(MCObjectStreamer &Streamer) : Streamer(Streamer) { | ||
assert(Streamer.getContext() | ||
.getObjectFileInfo() | ||
->getSFrameABIArch() | ||
.has_value()); | ||
SFrameABI = *Streamer.getContext().getObjectFileInfo()->getSFrameABIArch(); | ||
FDESubSectionStart = Streamer.getContext().createTempSymbol(); | ||
FRESubSectionStart = Streamer.getContext().createTempSymbol(); | ||
FRESubSectionEnd = Streamer.getContext().createTempSymbol(); | ||
} | ||
|
||
void EmitPreamble() { | ||
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. Not sure how I missed this in the first pass, but all these function names should use camelCase (i.e. |
||
Streamer.emitInt16(Magic); | ||
Streamer.emitInt8(static_cast<uint8_t>(Version::V2)); | ||
Streamer.emitInt8(0); | ||
} | ||
|
||
void EmitHeader() { | ||
EmitPreamble(); | ||
// sfh_abi_arch | ||
Streamer.emitInt8(static_cast<uint8_t>(SFrameABI)); | ||
// sfh_cfa_fixed_fp_offset | ||
Streamer.emitInt8(0); | ||
// sfh_cfa_fixed_ra_offset | ||
Streamer.emitInt8(0); | ||
// sfh_auxhdr_len | ||
Streamer.emitInt8(0); | ||
// shf_num_fdes | ||
Streamer.emitInt32(0); | ||
// shf_num_fres | ||
Streamer.emitInt32(0); | ||
// shf_fre_len | ||
Streamer.emitAbsoluteSymbolDiff(FRESubSectionEnd, FRESubSectionStart, | ||
sizeof(int32_t)); | ||
// shf_fdeoff. With no sfh_auxhdr, these immediately follow this header. | ||
Streamer.emitInt32(0); | ||
// shf_freoff | ||
Streamer.emitAbsoluteSymbolDiff(FRESubSectionStart, FDESubSectionStart, | ||
sizeof(uint32_t)); | ||
} | ||
|
||
void EmitFDEs() { Streamer.emitLabel(FDESubSectionStart); } | ||
|
||
void EmitFREs() { | ||
Streamer.emitLabel(FRESubSectionStart); | ||
Streamer.emitLabel(FRESubSectionEnd); | ||
} | ||
}; | ||
|
||
} // end anonymous namespace | ||
|
||
void MCSFrameEmitter::Emit(MCObjectStreamer &Streamer) { | ||
MCContext &Context = Streamer.getContext(); | ||
SFrameEmitterImpl Emitter(Streamer); | ||
|
||
MCSection *Section = Context.getObjectFileInfo()->getSFrameSection(); | ||
// Not strictly necessary, but gas always aligns to 8, so match that. | ||
jh7370 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Section->ensureMinAlignment(Align(8)); | ||
Streamer.switchSection(Section); | ||
MCSymbol *SectionStart = Context.createTempSymbol(); | ||
Streamer.emitLabel(SectionStart); | ||
Emitter.EmitHeader(); | ||
Emitter.EmitFDEs(); | ||
Emitter.EmitFREs(); | ||
} |
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 @@ | ||
// TODO: Add other architectures as they gain sframe support | ||
// REQUIRES: x86-registered-target | ||
// RUN: llvm-mc --assemble --filetype=obj --gsframe -triple x86_64 %s -o %t.o | ||
// RUN: llvm-readelf --sframe %t.o | FileCheck %s | ||
|
||
.cfi_sections .sframe | ||
|
||
f1: | ||
.cfi_startproc | ||
nop | ||
.cfi_endproc | ||
Sterling-Augustine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CHECK: SFrame section '.sframe' { | ||
// CHECK-NEXT: Header { | ||
// CHECK-NEXT: Magic: 0xDEE2 | ||
// CHECK-NEXT: Version: V2 (0x2) | ||
// CHECK-NEXT: Flags [ (0x0) | ||
// CHECK: ABI: AMD64EndianLittle (0x3) | ||
// CHECK-NEXT: CFA fixed FP offset (unused): 0 | ||
// CHECK-NEXT: CFA fixed RA offset: 0 | ||
// CHECK-NEXT: Auxiliary header length: 0 | ||
// CHECK-NEXT: Num FDEs: 0 | ||
// CHECK-NEXT: Num FREs: 0 | ||
// CHECK-NEXT: FRE subsection length: 0 | ||
// CHECK-NEXT: FDE subsection offset: 0 | ||
// CHECK-NEXT: FRE subsection offset: 0 |
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.