Commit cb6e95aa by Karl Schimpf

Modify how textual bitcode is injected into pnacl-sz.

Added command line flag "--bitcode-as-text", and triggered the acceptance of textual bitcode on this flag. To make sure this isn't added to the sandboxed translator, the reading of bitcode text is also dependent on the translator not being a minimal build. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4222 R=jvoung@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/1215463014 .
parent 713278ab
......@@ -3,26 +3,33 @@ set(LLVM_LINK_COMPONENTS
Core
IRReader
NaClBitReader
NaClBitTestUtils
Support
)
file(GLOB pnacl_sz_SRCS "src/*.cpp")
add_llvm_tool(pnacl-sz ${pnacl_sz_SRCS})
add_definitions(
if(PNACL_BROWSER_TRANSLATOR)
add_definitions(
-DALLOW_DUMP=0
-DALLOW_LLVM_CL=0
-DALLOW_LLVM_IR=0
-DALLOW_LLVM_IR_AS_INPUT=0
-DALLOW_DISABLE_IR_GEN=0
-DALLOW_MINIMAL_BUILD=1
-DPNACL_BROWSER_TRANSLATOR=1
)
else()
add_definitions(
-DALLOW_DUMP=1
-DALLOW_LLVM_CL=1
-DALLOW_LLVM_IR=1
-DALLOW_LLVM_IR_AS_INPUT=1
-DALLOW_DISABLE_IR_GEN=1
-DALLOW_MINIMAL_BUILD=0
-DINPUT_IS_TEXTUAL_BITCODE=0
-DPNACL_BROWSER_TRANSLATOR=0
)
if(PNACL_BROWSER_TRANSLATOR)
add_definitions(-DPNACL_BROWSER_TRANSLATOR=1)
else()
add_definitions(-DPNACL_BROWSER_TRANSLATOR=0)
endif()
target_link_libraries(pnacl-sz pthread)
......@@ -22,11 +22,10 @@ CXX.Flags += -std=gnu++11
ifeq ($(PNACL_BROWSER_TRANSLATOR),1)
CPP.Defines += -DALLOW_DUMP=0 -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \
-DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_DISABLE_IR_GEN=0 \
-DALLOW_MINIMAL_BUILD=1 -DPNACL_BROWSER_TRANSLATOR=1 \
-DINPUT_IS_TEXTUAL_BITCODE=0
-DALLOW_MINIMAL_BUILD=1 -DPNACL_BROWSER_TRANSLATOR=1
else
CPP.Defines += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
-DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_DISABLE_IR_GEN=1 \
-DALLOW_MINIMAL_BUILD=0 -DPNACL_BROWSER_TRANSLATOR=0 \
-DINPUT_IS_TEXTUAL_BITCODE=0
-DALLOW_MINIMAL_BUILD=0 -DPNACL_BROWSER_TRANSLATOR=0
endif
......@@ -86,13 +86,6 @@ else
-DALLOW_MINIMAL_BUILD=0
endif
ifdef TEXTUAL_BITCODE
BASE_CXX_DEFINES += -DINPUT_IS_TEXTUAL_BITCODE=1
OBJDIR := $(OBJDIR)+Tbc
else
BASE_CXX_DEFINES += -DINPUT_IS_TEXTUAL_BITCODE=0
endif
SB_CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=1
CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
......@@ -238,11 +231,7 @@ endif
# SHOW_BUILD_ATTS is an executable that is run to show what build
# attributes were used to build pnacl-sz.
ifdef TEXTUAL_BITCODE
SHOW_BUILD_ATTS = echo "Can't show build attributes when TEXTUAL_BITCODE=1"
else
SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
endif
SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
# Creates symbolic link so that testing is easier. Also runs
# pnacl-sz to verify that the defines flags have valid values,
......
......@@ -25,7 +25,6 @@ constexpr bool llvmCl() { return ALLOW_LLVM_CL; }
constexpr bool llvmIr() { return ALLOW_LLVM_IR; }
constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; }
constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; }
constexpr bool textualBitcode() { return INPUT_IS_TEXTUAL_BITCODE; }
// NDEBUG can be undefined, or defined to something arbitrary.
constexpr bool asserts() {
......
......@@ -314,6 +314,12 @@ cl::opt<bool> ReorderPooledConstants(
cl::desc("Reorder the layout of constants in constant pools"),
cl::init(false));
// Command line option for accepting textual bitcode.
cl::opt<bool> BitcodeAsText(
"bitcode-as-text",
cl::desc(
"Accept textual form of PNaCl bitcode records (i.e. not .ll assembly)"),
cl::init(false));
} // end of anonymous namespace
namespace Ice {
......@@ -442,6 +448,7 @@ void ClFlags::getParsedClFlags(ClFlags &OutFlags) {
void ClFlags::getParsedClFlagsExtra(ClFlagsExtra &OutFlagsExtra) {
OutFlagsExtra.setAlwaysExitSuccess(AlwaysExitSuccess);
OutFlagsExtra.setBitcodeAsText(BitcodeAsText);
OutFlagsExtra.setBuildOnRead(BuildOnRead);
OutFlagsExtra.setGenerateBuildAtts(GenerateBuildAtts);
OutFlagsExtra.setLLVMVerboseErrors(LLVMVerboseErrors);
......
......@@ -43,6 +43,9 @@ public:
bool getLLVMVerboseErrors() const { return LLVMVerboseErrors; }
void setLLVMVerboseErrors(bool NewValue) { LLVMVerboseErrors = NewValue; }
bool getBitcodeAsText() const { return BitcodeAsText; }
void setBitcodeAsText(bool NewValue) { BitcodeAsText = NewValue; }
llvm::NaClFileFormat getInputFileFormat() const { return InputFileFormat; }
void setInputFileFormat(llvm::NaClFileFormat NewValue) {
InputFileFormat = NewValue;
......@@ -64,6 +67,7 @@ public:
private:
bool AlwaysExitSuccess = false;
bool BitcodeAsText = false;
bool BuildOnRead = false;
bool GenerateBuildAtts = false;
bool LLVMVerboseErrors = false;
......
......@@ -21,8 +21,6 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
// Include code to handle converting textual bitcode records to binary (for
// INPUT_IS_TEXTUAL_BITCODE).
#include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_os_ostream.h"
......@@ -39,10 +37,6 @@ namespace Ice {
namespace {
static_assert(!(BuildDefs::textualBitcode() && PNACL_BROWSER_TRANSLATOR),
"Can not define INPUT_IS_TEXTUAL_BITCODE when building browswer "
"translator");
// Define a SmallVector backed buffer as a data stream, so that it
// can hold the generated binary version of the textual bitcode in the
// input file.
......@@ -64,12 +58,12 @@ TextDataStreamer *TextDataStreamer::create(const IceString &Filename,
llvm::raw_string_ostream ErrStrm(*Err);
if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode(
Filename, Streamer->BitcodeBuffer, &ErrStrm)) {
ErrStrm << EC.message(); // << "\n";
ErrStrm << EC.message();
ErrStrm.flush();
delete Streamer;
return nullptr;
}
// ErrStrm.flush();
ErrStrm.flush();
return Streamer;
}
......@@ -151,9 +145,13 @@ void CLCompileServer::run() {
} break;
}
if (BuildDefs::minimal() && ExtraFlags.getBitcodeAsText())
llvm::report_fatal_error("Can't specify 'bitcode-as-text' flag in "
"minimal build");
IceString StrError;
std::unique_ptr<llvm::DataStreamer> InputStream(
BuildDefs::textualBitcode()
(!BuildDefs::minimal() && ExtraFlags.getBitcodeAsText())
? TextDataStreamer::create(ExtraFlags.getIRFilename(), &StrError)
: llvm::getDataFileStreamer(ExtraFlags.getIRFilename(), &StrError));
if (!StrError.empty() || !InputStream) {
......
......@@ -2,7 +2,7 @@
SUBZERO_LEVEL := ..
TOOLNAME := pnacl-sz
LINK_COMPONENTS := irreader bitreader naclbitreader naclanalysis core support
LINK_COMPONENTS := irreader bitreader naclbitreader naclbittestutils naclanalysis core support
# This tool has no plugins, optimize startup time.
TOOL_NO_EXPORTS := 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment