Skip to content

Commit 7f3b467

Browse files
committed
AsmPrinter + BTFDebug
1 parent bb61d16 commit 7f3b467

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ class LLVM_ABI AsmPrinter : public MachineFunctionPass {
110110
/// generating (such as the current section etc).
111111
std::unique_ptr<MCStreamer> OutStreamer;
112112

113-
/// The VFS to resolve asm include directives.
114-
IntrusiveRefCntPtr<vfs::FileSystem> VFS;
115-
116113
/// The current machine function.
117114
MachineFunction *MF = nullptr;
118115

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
477477
}
478478

479479
bool AsmPrinter::doInitialization(Module &M) {
480-
VFS = vfs::getRealFileSystem();
481480
auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
482481
MMI = MMIWP ? &MMIWP->getMMI() : nullptr;
483482
HasSplitStack = false;

llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
9898

9999
unsigned BufNum = addInlineAsmDiagBuffer(Str, LocMDNode);
100100
SourceMgr &SrcMgr = *MMI->getContext().getInlineSourceManager();
101-
SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
102-
SrcMgr.setVirtualFileSystem(VFS);
101+
// FIXME(sandboxing): This is not executed in tests, but might be common.
102+
// Propagating vfs::FileSystem here is lots of work,
103+
// consider bypassing the sandbox.
104+
if (!MCOptions.IASSearchPaths.empty()) {
105+
SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
106+
SrcMgr.setVirtualFileSystem(vfs::getRealFileSystem());
107+
}
103108

104109
std::unique_ptr<MCAsmParser> Parser(
105110
createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));

llvm/lib/Target/BPF/BTFDebug.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/MC/MCObjectFileInfo.h"
2424
#include "llvm/MC/MCSectionELF.h"
2525
#include "llvm/MC/MCStreamer.h"
26+
#include "llvm/Support/IOSandbox.h"
2627
#include "llvm/Support/LineIterator.h"
2728
#include "llvm/Support/MemoryBuffer.h"
2829
#include "llvm/Target/TargetLoweringObjectFile.h"
@@ -1017,12 +1018,17 @@ std::string BTFDebug::populateFileContent(const DIFile *File) {
10171018
std::string Line;
10181019
Content.push_back(Line); // Line 0 for empty string
10191020

1021+
auto LoadFile = [](StringRef FileName) {
1022+
// FIXME(sandboxing): Propagating vfs::FileSystem here is lots of work.
1023+
[[maybe_unused]] auto BypassSandbox = sys::sandbox::scopedDisable();
1024+
return MemoryBuffer::getFile(FileName);
1025+
};
1026+
10201027
std::unique_ptr<MemoryBuffer> Buf;
10211028
auto Source = File->getSource();
10221029
if (Source)
10231030
Buf = MemoryBuffer::getMemBufferCopy(*Source);
1024-
else if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
1025-
MemoryBuffer::getFile(FileName))
1031+
else if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = LoadFile(FileName))
10261032
Buf = std::move(*BufOrErr);
10271033
if (Buf)
10281034
for (line_iterator I(*Buf, false), E; I != E; ++I)

0 commit comments

Comments
 (0)