aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLai Wei-Chih <Robert.Lai@mediatek.com>2013-05-22 17:11:28 +0800
committerAndrew Hsieh <andrewhsieh@google.com>2015-03-24 11:54:11 -0700
commit05fc2631081d6bfcaab1be6ac1eee6ce2ecde9bd (patch)
tree37fa9b942b14979973d1ad075148f818be5e3ac0
parentd0a379abb38851da152cf716d566b2654909df90 (diff)
downloadllvm-05fc2631081d6bfcaab1be6ac1eee6ce2ecde9bd.tar.gz
[ndk][pndk] Add 2 tags in LLVMWrap.
* kAndroidBitcodeType Generate this bitcode for shared object or executable. * kAndroidLDFlags Store linker flags for this bitcode.
-rw-r--r--include/llvm/Wrap/BCHeaderField.h10
-rw-r--r--include/llvm/Wrap/BitcodeWrapper.h16
-rw-r--r--include/llvm/Wrap/bitcode_wrapperer.h11
-rw-r--r--lib/Wrap/BitcodeWrapper.cpp3
-rw-r--r--lib/Wrap/bitcode_wrapperer.cpp39
5 files changed, 66 insertions, 13 deletions
diff --git a/include/llvm/Wrap/BCHeaderField.h b/include/llvm/Wrap/BCHeaderField.h
index fd8d585f009..e04a593b631 100644
--- a/include/llvm/Wrap/BCHeaderField.h
+++ b/include/llvm/Wrap/BCHeaderField.h
@@ -34,10 +34,18 @@ class BCHeaderField {
kInvalid = 0,
kBitcodeHash = 1,
kAndroidCompilerVersion = 0x4001,
- kAndroidOptimizationLevel = 0x4002
+ kAndroidOptimizationLevel = 0x4002,
+ kAndroidBitcodeType = 0x5001,
+ kAndroidLDFlags = 0x5002
} Tag;
typedef uint16_t FixedSubfield;
+ typedef enum {
+ BC_Relocatable = 0x00000000,
+ BC_SharedObject = 0x00000001,
+ BC_Executable = 0x00000002
+ } BitcodeType;
+
BCHeaderField(Tag ID, size_t len, uint8_t* data) :
ID_(ID), len_(len), data_(data) {}
size_t GetTotalSize() {
diff --git a/include/llvm/Wrap/BitcodeWrapper.h b/include/llvm/Wrap/BitcodeWrapper.h
index a5ce2624004..8ed1a77d191 100644
--- a/include/llvm/Wrap/BitcodeWrapper.h
+++ b/include/llvm/Wrap/BitcodeWrapper.h
@@ -21,6 +21,7 @@
#include <cstddef>
#include <stdint.h>
+#include <vector>
struct AndroidBitcodeWrapper {
uint32_t Magic;
@@ -54,6 +55,8 @@ class BitcodeWrapper {
uint32_t mTargetAPI;
uint32_t mCompilerVersion;
uint32_t mOptimizationLevel;
+ uint32_t mBitcodeType;
+ std::string mLDFlags;
public:
/**
@@ -108,6 +111,19 @@ class BitcodeWrapper {
return mOptimizationLevel;
}
+ /**
+ * \return bitcode type for this bitcode.
+ */
+ uint32_t getBitcodeType() const {
+ return mBitcodeType;
+ }
+
+ /**
+ * \return linker flags for this bitcode.
+ */
+ const std::string& getLDFlags() const {
+ return mLDFlags;
+ }
};
/**
diff --git a/include/llvm/Wrap/bitcode_wrapperer.h b/include/llvm/Wrap/bitcode_wrapperer.h
index 26b9664f8a1..948a113ce3a 100644
--- a/include/llvm/Wrap/bitcode_wrapperer.h
+++ b/include/llvm/Wrap/bitcode_wrapperer.h
@@ -22,6 +22,7 @@
#include <stdint.h>
#include <stddef.h>
+#include <string>
#include <vector>
#include "llvm/Wrap/support_macros.h"
@@ -91,6 +92,14 @@ class BitcodeWrapperer {
return android_optimization_level_;
}
+ uint32_t getAndroidBitcodeType() {
+ return android_bitcode_type_;
+ }
+
+ std::string getAndroidLDFlags() {
+ return android_ldflags_;
+ }
+
~BitcodeWrapperer();
private:
@@ -204,6 +213,8 @@ class BitcodeWrapperer {
uint32_t android_target_api_;
uint32_t android_compiler_version_;
uint32_t android_optimization_level_;
+ uint32_t android_bitcode_type_;
+ std::string android_ldflags_;
// PNaCl bitcode version
uint32_t pnacl_bc_version_;
diff --git a/lib/Wrap/BitcodeWrapper.cpp b/lib/Wrap/BitcodeWrapper.cpp
index d779d3a27c7..2face5e70c9 100644
--- a/lib/Wrap/BitcodeWrapper.cpp
+++ b/lib/Wrap/BitcodeWrapper.cpp
@@ -35,6 +35,8 @@ BitcodeWrapper::BitcodeWrapper(const char *bitcode, size_t bitcodeSize)
mTargetAPI = wrapperer.getAndroidTargetAPI();
mCompilerVersion = wrapperer.getAndroidCompilerVersion();
mOptimizationLevel = wrapperer.getAndroidOptimizationLevel();
+ mBitcodeType = wrapperer.getAndroidBitcodeType();
+ mLDFlags = wrapperer.getAndroidLDFlags();
} else if (wrapperer.IsInputBitcodeFile()) {
mFileType = BC_RAW;
}
@@ -49,4 +51,3 @@ BitcodeWrapper::~BitcodeWrapper() {
bool BitcodeWrapper::unwrap() {
return mFileType != BC_NOT_BC;
}
-
diff --git a/lib/Wrap/bitcode_wrapperer.cpp b/lib/Wrap/bitcode_wrapperer.cpp
index 65f94b7c67a..67c83c7c5f1 100644
--- a/lib/Wrap/bitcode_wrapperer.cpp
+++ b/lib/Wrap/bitcode_wrapperer.cpp
@@ -43,13 +43,14 @@ static const uint32_t kAndroidHeaderVersion = 0;
static const uint32_t kAndroidTargetAPI = 0;
static const uint32_t kAndroidDefaultCompilerVersion = 0;
static const uint32_t kAndroidDefaultOptimizationLevel = 3;
+static const uint32_t kAndroidBitcodeType = 0;
// PNaCl bitcode version number.
static const uint32_t kPnaclBitcodeVersion = 0;
// Max size for variable fields. Currently only used for writing them
// out to files (the parsing works for arbitrary sizes).
-static const size_t kMaxVariableFieldSize = 256;
+static const size_t kMaxVariableFieldSize = 512;
BitcodeWrapperer::BitcodeWrapperer(WrapperInput* infile, WrapperOutput* outfile)
: infile_(infile),
@@ -64,6 +65,7 @@ BitcodeWrapperer::BitcodeWrapperer(WrapperInput* infile, WrapperOutput* outfile)
android_target_api_(kAndroidTargetAPI),
android_compiler_version_(kAndroidDefaultCompilerVersion),
android_optimization_level_(kAndroidDefaultOptimizationLevel),
+ android_bitcode_type_(kAndroidBitcodeType),
pnacl_bc_version_(0),
error_(false) {
buffer_.resize(kBitcodeWrappererBufferSize);
@@ -226,24 +228,39 @@ bool BitcodeWrapperer::ParseWrapperHeader() {
return false;
}
- struct IntFieldHelper {
+ struct FieldHelper {
BCHeaderField::FixedSubfield tag;
- uint16_t len;
- uint32_t val;
+ BCHeaderField::FixedSubfield len;
+ union {
+ uint32_t int32;
+ uint8_t char8[kMaxVariableFieldSize];
+ }val;
};
- IntFieldHelper tempIntField;
+ FieldHelper tempField;
switch (field.getID()) {
case BCHeaderField::kAndroidCompilerVersion:
- if (field.Write((uint8_t*)&tempIntField,
- sizeof(tempIntField))) {
- android_compiler_version_ = tempIntField.val;
+ if (field.Write((uint8_t*)&tempField,
+ sizeof(tempField))) {
+ android_compiler_version_ = tempField.val.int32;
}
break;
case BCHeaderField::kAndroidOptimizationLevel:
- if (field.Write((uint8_t*)&tempIntField,
- sizeof(tempIntField))) {
- android_optimization_level_ = tempIntField.val;
+ if (field.Write((uint8_t*)&tempField,
+ sizeof(tempField))) {
+ android_optimization_level_ = tempField.val.int32;
+ }
+ break;
+ case BCHeaderField::kAndroidBitcodeType:
+ if (field.Write((uint8_t*)&tempField,
+ sizeof(tempField))) {
+ android_bitcode_type_ = tempField.val.int32;
+ }
+ break;
+ case BCHeaderField::kAndroidLDFlags:
+ if (field.Write((uint8_t*)&tempField,
+ sizeof(tempField))) {
+ android_ldflags_ = (char *) tempField.val.char8;
}
break;
default: