diff options
author | Stephen Hines <srhines@google.com> | 2013-08-06 13:39:28 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-08-06 13:39:28 -0700 |
commit | 1ecad8f8e96b67d5f8c43af44375abafa7d40eff (patch) | |
tree | f2912deb3df0016cd7f7d0ee65183a3a1690e578 | |
parent | bd84ef795e2ca69d7236f65d208695542830328a (diff) | |
parent | baa6b9d53c2675f20ae6a8d7796b6d530cca8fa7 (diff) | |
download | libbcc-1ecad8f8e96b67d5f8c43af44375abafa7d40eff.tar.gz |
am baa6b9d5: Remove libbcc\'s dependence on mclinker.
* commit 'baa6b9d53c2675f20ae6a8d7796b6d530cca8fa7':
Remove libbcc's dependence on mclinker.
-rwxr-xr-x | Android.mk | 43 | ||||
-rw-r--r-- | CleanSpec.mk | 4 | ||||
-rw-r--r-- | include/bcc/Linker.h | 101 | ||||
-rw-r--r-- | include/bcc/Support/LinkerConfig.h | 120 | ||||
-rw-r--r-- | include/bcc/Support/MemoryFactory.h | 46 | ||||
-rw-r--r-- | include/bcc/Support/TargetLinkerConfigs.h | 96 | ||||
-rw-r--r-- | lib/Core/Android.mk | 7 | ||||
-rw-r--r-- | lib/Core/Linker.cpp | 181 | ||||
-rw-r--r-- | lib/Support/Android.mk | 10 | ||||
-rw-r--r-- | lib/Support/Initialization.cpp | 15 | ||||
-rw-r--r-- | lib/Support/LinkerConfig.cpp | 341 | ||||
-rw-r--r-- | lib/Support/TargetLinkerConfigs.cpp | 183 | ||||
-rw-r--r-- | libbcc-device-build.mk | 4 | ||||
-rw-r--r-- | libbcc-host-build.mk | 2 | ||||
-rw-r--r-- | libbcc.mk | 5 | ||||
-rw-r--r-- | tools/mcld/Android.mk | 57 | ||||
-rw-r--r-- | tools/mcld/Main.cpp | 383 |
17 files changed, 15 insertions, 1583 deletions
@@ -31,18 +31,6 @@ libbcc_WHOLE_STATIC_LIBRARIES += \ libbccCore \ libbccSupport -libmcld_STATIC_LIBRARIES += \ - libmcldCodeGen \ - libmcldTarget \ - libmcldLDVariant \ - libmcldMC \ - libmcldObject \ - libmcldFragment \ - libmcldCore \ - libmcldSupport \ - libmcldADT \ - libmcldLD - #===================================================================== # Calculate SHA1 checksum for libbcc.so, libRS.so and libclcore.bc #===================================================================== @@ -98,27 +86,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := $(libbcc_WHOLE_STATIC_LIBRARIES) LOCAL_WHOLE_STATIC_LIBRARIES += librsloader -ifeq ($(TARGET_ARCH),arm) - LOCAL_WHOLE_STATIC_LIBRARIES += \ - libmcldARMTarget \ - libmcldARMInfo -else - ifeq ($(TARGET_ARCH), mips) - LOCAL_WHOLE_STATIC_LIBRARIES += \ - libmcldMipsTarget \ - libmcldMipsInfo - else - ifeq ($(TARGET_ARCH),x86) # We don't support x86-64 right now - LOCAL_WHOLE_STATIC_LIBRARIES += \ - libmcldX86Target \ - libmcldX86Info - else - $(error Unsupported TARGET_ARCH $(TARGET_ARCH)) - endif - endif -endif - -LOCAL_WHOLE_STATIC_LIBRARIES += $(libmcld_STATIC_LIBRARIES) LOCAL_SHARED_LIBRARIES := libbcinfo libLLVM libdl libutils libcutils liblog libstlport # Modules that need get installed if and only if the target libbcc.so is @@ -157,16 +124,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES += $(libbcc_WHOLE_STATIC_LIBRARIES) LOCAL_WHOLE_STATIC_LIBRARIES += librsloader -LOCAL_WHOLE_STATIC_LIBRARIES += \ - libmcldARMTarget \ - libmcldARMInfo \ - libmcldMipsTarget \ - libmcldMipsInfo \ - libmcldX86Target \ - libmcldX86Info - -LOCAL_WHOLE_STATIC_LIBRARIES += $(libmcld_STATIC_LIBRARIES) - LOCAL_STATIC_LIBRARIES += \ libutils \ libcutils \ diff --git a/CleanSpec.mk b/CleanSpec.mk index a7ef88d..1d4b562 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -57,6 +57,10 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libclcore.bc_i $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libclcore_neon.bc_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libclcore*.bc_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libbcinfo_intermediates) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libbc*_intermediates) +$(call add-clean-step, rm -rf $(HOST_OUT)/obj/STATIC_LIBRARIES/libbc*_intermediates) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libbc*_intermediates) +$(call add-clean-step, rm -rf $(HOST_OUT)/obj/SHARED_LIBRARIES/libbc*_intermediates) # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST diff --git a/include/bcc/Linker.h b/include/bcc/Linker.h deleted file mode 100644 index 43a8839..0000000 --- a/include/bcc/Linker.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BCC_LINKER_H -#define BCC_LINKER_H - -#include <string> - -namespace mcld { - -class Module; -class IRBuilder; -class LinkerConfig; -class Linker; -class Input; -class MemoryArea; - -namespace sys { namespace fs { - -class Path; - -} } // end namespace sys::fs - -} // end namespace mcld - -namespace bcc { - -class LinkerConfig; - -class Linker { -public: - enum ErrorCode { - kSuccess, - kDoubleConfig, - kDelegateLDInfo, - kFindNameSpec, - kOpenObjectFile, - kOpenMemory, - kNotConfig, - kNotSetUpOutput, - kOpenOutput, - kReadSections, - kReadSymbols, - kAddAdditionalSymbols, - kMaxErrorCode - }; - - static const char *GetErrorString(enum ErrorCode pErrCode); - -private: - const mcld::LinkerConfig *mLDConfig; - mcld::Module *mModule; - mcld::Linker *mLinker; - mcld::IRBuilder *mBuilder; - std::string mSOName; - std::string mOutputPath; - int mOutputHandler; - -public: - Linker(); - - Linker(const LinkerConfig& pConfig); - - ~Linker(); - - enum ErrorCode config(const LinkerConfig& pConfig); - - enum ErrorCode addNameSpec(const std::string &pNameSpec); - - enum ErrorCode addObject(const std::string &pObjectPath); - - enum ErrorCode addObject(void* pMemory, size_t pSize); - - enum ErrorCode addCode(void* pMemory, size_t pSize); - - enum ErrorCode setOutput(const std::string &pPath); - - enum ErrorCode setOutput(int pFileHandler); - - enum ErrorCode link(); - -private: - enum ErrorCode extractFiles(const LinkerConfig& pConfig); -}; - -} // end namespace bcc - -#endif // BCC_LINKER_H diff --git a/include/bcc/Support/LinkerConfig.h b/include/bcc/Support/LinkerConfig.h deleted file mode 100644 index 09a08ec..0000000 --- a/include/bcc/Support/LinkerConfig.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BCC_SUPPORT_LINKER_CONFIG_H -#define BCC_SUPPORT_LINKER_CONFIG_H - -#include <string> - -#include <mcld/LinkerConfig.h> -#include <mcld/Support/TargetRegistry.h> -#include <mcld/LD/DiagnosticLineInfo.h> -#include <mcld/LD/DiagnosticPrinter.h> - -namespace bcc { - -class LinkerConfig { -private: - //===--------------------------------------------------------------------===// - // Available Configurations - //===--------------------------------------------------------------------===// - const std::string mTriple; - std::string mSOName; - -private: - //===--------------------------------------------------------------------===// - // These are generated by LinkerConfig during initialize(). - //===--------------------------------------------------------------------===// - const mcld::Target *mTarget; - bool initializeTarget(); - - mcld::LinkerConfig *mLDConfig; - bool initializeLDInfo(); - - mcld::DiagnosticLineInfo *mDiagLineInfo; - mcld::DiagnosticPrinter *mDiagPrinter; - bool initializeDiagnostic(); - -public: - enum ZOptionEnum { - kCombReloc = 1 << 0, ///< [on] -z combreloc, [off] -z nocombreloc - kDefs = 1 << 1, ///< -z defs - kExecStack = 1 << 2, ///< [on] -z execstack, [off] -z noexecstack - kInitFirst = 1 << 3, ///< -z initfirst - kInterPose = 1 << 4, ///< -z interpose - kLoadFltr = 1 << 5, ///< -z loadfltr - kMulDefs = 1 << 6, ///< -z muldefs - kNoCopyReloc = 1 << 7, ///< -z nocopyreloc - kNoDefaultLib = 1 << 8, ///< -z nodefaultlib - kNoDelete = 1 << 9, ///< -z nodelete - kNoDLOpen = 1 << 10, ///< -z nodlopen - kNoDump = 1 << 11, ///< -z nodump - kRelro = 1 << 12, ///< [on] -z relro, [off] -z norelro - kLazy = 1 << 13, ///< [on] -z lazy, [off] -z now - kOrigin = 1 << 14, ///< -z origin - kZOptionMask = 0xFFFF - }; - -public: - //===--------------------------------------------------------------------===// - // Getters - //===--------------------------------------------------------------------===// - inline const std::string &getTriple() const - { return mTriple; } - - inline const mcld::Target *getTarget() const - { return mTarget; } - - inline mcld::LinkerConfig* getLDConfig() - { return mLDConfig; } - - inline const mcld::LinkerConfig* getLDConfig() const - { return mLDConfig; } - - bool isShared() const; - - inline std::string getSOName() const - { return mSOName; } - - void setShared(bool pEnable = true); - - void setBsymbolic(bool pEnable = true); - - void setDefineCommon(bool pEnable = true); - - void setSOName(const std::string &pSOName); - - void setDyld(const std::string &pDyld); - - void setSysRoot(const std::string &pSysRoot); - - void setZOption(unsigned int pOptions); - - void addWrap(const std::string &pWrapSymbol); - - void addPortable(const std::string &pPortableSymbol); - - void addSearchDir(const std::string &pDir); - -public: - LinkerConfig(const std::string& pTriple); - - virtual ~LinkerConfig(); -}; - -} // end namespace bcc - -#endif // BCC_SUPPORT_LINKER_CONFIG_H diff --git a/include/bcc/Support/MemoryFactory.h b/include/bcc/Support/MemoryFactory.h deleted file mode 100644 index ffbf25e..0000000 --- a/include/bcc/Support/MemoryFactory.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BCC_SUPPORT_MEMORY_FACTORY_H -#define BCC_SUPPORT_MEMORY_FACTORY_H - -#include <mcld/Support/FileHandle.h> -#include <mcld/Support/MemoryAreaFactory.h> - -namespace mcld { -class MemoryArea; -} // end namespace mcld - -namespace bcc { - -class MemoryFactory : public mcld::MemoryAreaFactory { -public: - MemoryFactory() : mcld::MemoryAreaFactory(32) { } - - ~MemoryFactory() { } - - using mcld::MemoryAreaFactory::produce; - - mcld::MemoryArea* produce(void *pMemBuffer, size_t pSize) - { return mcld::MemoryAreaFactory::create(pMemBuffer, pSize); } - - mcld::MemoryArea* produce(int pFD) - { return mcld::MemoryAreaFactory::create(pFD, mcld::FileHandle::Unknown); } -}; - -} // end namespace bcc - -#endif // BCC_SUPPORT_MEMORY_FACTORY_H diff --git a/include/bcc/Support/TargetLinkerConfigs.h b/include/bcc/Support/TargetLinkerConfigs.h deleted file mode 100644 index fd7b7df..0000000 --- a/include/bcc/Support/TargetLinkerConfigs.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BCC_SUPPORT_TARGET_LINKER_CONFIGS_H -#define BCC_SUPPORT_TARGET_LINKER_CONFIGS_H - -#include <string> - -#include "bcc/Config/Config.h" -#include "bcc/Support/LinkerConfig.h" - -namespace bcc { - -//===----------------------------------------------------------------------===// -// ARM -//===----------------------------------------------------------------------===// -#if defined(PROVIDE_ARM_CODEGEN) -class ARMLinkerConfig : public LinkerConfig { -public: - ARMLinkerConfig(); -}; -#endif // defined(PROVIDE_ARM_CODEGEN) - -//===----------------------------------------------------------------------===// -// MIPS -//===----------------------------------------------------------------------===// -#if defined(PROVIDE_MIPS_CODEGEN) -class MipsLinkerConfig : public LinkerConfig { -public: - MipsLinkerConfig(); -}; -#endif // defined(PROVIDE_MIPS_CODEGEN) - -//===----------------------------------------------------------------------===// -// X86 and X86_64 -//===----------------------------------------------------------------------===// -#if defined(PROVIDE_X86_CODEGEN) -class X86FamilyLinkerConfigBase : public LinkerConfig { -public: - X86FamilyLinkerConfigBase(const std::string& pTriple); -}; - -class X86_32LinkerConfig : public X86FamilyLinkerConfigBase { -public: - X86_32LinkerConfig(); -}; - -class X86_64LinkerConfig : public X86FamilyLinkerConfigBase { -public: - X86_64LinkerConfig(); -}; -#endif // defined(PROVIDE_X86_CODEGEN) - -//===----------------------------------------------------------------------===// -// Default target -//===----------------------------------------------------------------------===// -class DefaultLinkerConfig : public -#if defined (DEFAULT_ARM_CODEGEN) - ARMLinkerConfig -#elif defined (DEFAULT_MIPS_CODEGEN) - MipsLinkerConfig -#elif defined (DEFAULT_X86_CODEGEN) - X86_32LinkerConfig -#elif defined (DEFAULT_X86_64_CODEGEN) - X86_64LinkerConfig -#else -# error "Unsupported Default Target!" -#endif -{ }; - -#if !defined(TARGET_BUILD) -//===----------------------------------------------------------------------===// -// General target -//===----------------------------------------------------------------------===// -class GeneralLinkerConfig : public LinkerConfig { -public: - GeneralLinkerConfig(const std::string& pTriple); -}; -#endif // !defined(TARGET_BUILD) - -} // end namespace bcc - -#endif // BCC_SUPPORT_LINKER_CONFIG_H diff --git a/lib/Core/Android.mk b/lib/Core/Android.mk index 1d5d5af..12bb1b5 100644 --- a/lib/Core/Android.mk +++ b/lib/Core/Android.mk @@ -25,7 +25,6 @@ libbcc_core_SRC_FILES := \ BCCContext.cpp \ BCCContextImpl.cpp \ Compiler.cpp \ - Linker.cpp \ Script.cpp \ Source.cpp @@ -43,8 +42,7 @@ LOCAL_SRC_FILES := $(libbcc_core_SRC_FILES) include $(LIBBCC_DEVICE_BUILD_MK) include $(LIBBCC_GEN_CONFIG_MK) -include $(MCLD_DEVICE_BUILD_MK) -#include $(LLVM_DEVICE_BUILD_MK) +include $(LLVM_DEVICE_BUILD_MK) include $(BUILD_STATIC_LIBRARY) @@ -62,6 +60,5 @@ LOCAL_SRC_FILES := $(libbcc_core_SRC_FILES) include $(LIBBCC_HOST_BUILD_MK) include $(LIBBCC_GEN_CONFIG_MK) -include $(MCLD_HOST_BUILD_MK) -#include $(LLVM_HOST_BUILD_MK) +include $(LLVM_HOST_BUILD_MK) include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/lib/Core/Linker.cpp b/lib/Core/Linker.cpp deleted file mode 100644 index 87bc389..0000000 --- a/lib/Core/Linker.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bcc/Linker.h" -#include "bcc/Support/LinkerConfig.h" -#include "bcc/Support/Log.h" - -#include <llvm/Support/ELF.h> - -#include <mcld/Module.h> -#include <mcld/IRBuilder.h> -#include <mcld/MC/MCLDInput.h> -#include <mcld/Linker.h> -#include <mcld/LD/LDSection.h> -#include <mcld/LD/LDContext.h> -#include <mcld/Support/Path.h> - -using namespace bcc; - -const char* Linker::GetErrorString(enum Linker::ErrorCode pErrCode) { - static const char* ErrorString[] = { - /* kSuccess */ - "Successfully compiled.", - /* kDoubleConfig */ - "Configure Linker twice.", - /* kDelegateLDInfo */ - "Cannot get linker information", - /* kFindNameSpec */ - "Cannot find -lnamespec", - /* kOpenObjectFile */ - "Cannot open object file", - /* kNotConfig */ - "Linker::config() is not called", - /* kNotSetUpOutput */ - "Linker::setOutput() is not called before add input files", - /* kOpenOutput */ - "Cannot open output file", - /* kReadSections */ - "Cannot read sections", - /* kReadSymbols */ - "Cannot read symbols", - /* kAddAdditionalSymbols */ - "Cannot add standard and target symbols", - /* kMaxErrorCode */ - "(Unknown error code)" - }; - - if (pErrCode > kMaxErrorCode) { - pErrCode = kMaxErrorCode; - } - - return ErrorString[ static_cast<size_t>(pErrCode) ]; -} - -//===----------------------------------------------------------------------===// -// Linker -//===----------------------------------------------------------------------===// -Linker::Linker() - : mLDConfig(NULL), mModule(NULL), mLinker(NULL), mBuilder(NULL), - mOutputHandler(-1) { -} - -Linker::Linker(const LinkerConfig& pConfig) - : mLDConfig(NULL), mModule(NULL), mLinker(NULL), mBuilder(NULL), - mOutputHandler(-1) { - - const std::string &triple = pConfig.getTriple(); - - enum ErrorCode err = config(pConfig); - if (kSuccess != err) { - ALOGE("%s (%s)", GetErrorString(err), triple.c_str()); - return; - } - - return; -} - -Linker::~Linker() { - delete mModule; - delete mLinker; - delete mBuilder; -} - -enum Linker::ErrorCode Linker::extractFiles(const LinkerConfig& pConfig) { - mLDConfig = pConfig.getLDConfig(); - if (mLDConfig == NULL) { - return kDelegateLDInfo; - } - return kSuccess; -} - -enum Linker::ErrorCode Linker::config(const LinkerConfig& pConfig) { - if (mLDConfig != NULL) { - return kDoubleConfig; - } - - extractFiles(pConfig); - - mModule = new mcld::Module(mLDConfig->options().soname()); - - mBuilder = new mcld::IRBuilder(*mModule, *mLDConfig); - - mLinker = new mcld::Linker(); - - mLinker->config(const_cast<mcld::LinkerConfig&>(*mLDConfig)); - - return kSuccess; -} - -enum Linker::ErrorCode Linker::addNameSpec(const std::string &pNameSpec) { - mcld::Input* input = mBuilder->ReadInput(pNameSpec); - if (NULL == input) - return kFindNameSpec; - return kSuccess; -} - -/// addObject - Add a object file by the filename. -enum Linker::ErrorCode Linker::addObject(const std::string &pObjectPath) { - mcld::Input* input = mBuilder->ReadInput(pObjectPath, pObjectPath); - if (NULL == input) - return kOpenObjectFile; - return kSuccess; -} - -/// addObject - Add a piece of memory. The memory is of ELF format. -enum Linker::ErrorCode Linker::addObject(void* pMemory, size_t pSize) { - mcld::Input* input = mBuilder->ReadInput("NAN", pMemory, pSize); - if (NULL == input) - return kOpenMemory; - return kSuccess; -} - -enum Linker::ErrorCode Linker::addCode(void* pMemory, size_t pSize) { - mcld::Input* input = mBuilder->CreateInput("NAN", "NAN", mcld::Input::Object); - mcld::LDSection* sect = mBuilder->CreateELFHeader(*input, ".text", - llvm::ELF::SHT_PROGBITS, - llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR, - 0x1); - mcld::SectionData* data = mBuilder->CreateSectionData(*sect); - mcld::Fragment* frag = mBuilder->CreateRegion(pMemory, pSize); - mBuilder->AppendFragment(*frag, *data); - return kSuccess; -} - -enum Linker::ErrorCode Linker::setOutput(const std::string &pPath) { - mOutputPath = pPath; - return kSuccess; -} - -enum Linker::ErrorCode Linker::setOutput(int pFileHandler) { - mOutputHandler = pFileHandler; - return kSuccess; -} - -enum Linker::ErrorCode Linker::link() { - mLinker->link(*mModule, *mBuilder); - if (!mOutputPath.empty()) { - mLinker->emit(mOutputPath); - return kSuccess; - } - - if (-1 != mOutputHandler) { - mLinker->emit(mOutputHandler); - return kSuccess; - } - return kNotSetUpOutput; -} - diff --git a/lib/Support/Android.mk b/lib/Support/Android.mk index ca4aa61..1abe4c2 100644 --- a/lib/Support/Android.mk +++ b/lib/Support/Android.mk @@ -27,11 +27,9 @@ libbcc_support_SRC_FILES := \ FileBase.cpp \ Initialization.cpp \ InputFile.cpp \ - LinkerConfig.cpp \ OutputFile.cpp \ Sha1Util.cpp \ - TargetCompilerConfigs.cpp \ - TargetLinkerConfigs.cpp + TargetCompilerConfigs.cpp #===================================================================== # Device Static Library: libbccSupport @@ -48,8 +46,7 @@ LOCAL_SRC_FILES := $(libbcc_support_SRC_FILES) include $(LIBBCC_DEVICE_BUILD_MK) include $(LIBBCC_GEN_CONFIG_MK) -include $(MCLD_DEVICE_BUILD_MK) -#include $(LLVM_DEVICE_BUILD_MK) +include $(LLVM_DEVICE_BUILD_MK) include $(BUILD_STATIC_LIBRARY) @@ -69,6 +66,5 @@ LOCAL_SRC_FILES := \ include $(LIBBCC_HOST_BUILD_MK) include $(LIBBCC_GEN_CONFIG_MK) -include $(MCLD_HOST_BUILD_MK) -#include $(LLVM_HOST_BUILD_MK) +include $(LLVM_HOST_BUILD_MK) include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/lib/Support/Initialization.cpp b/lib/Support/Initialization.cpp index 32be882..b41962c 100644 --- a/lib/Support/Initialization.cpp +++ b/lib/Support/Initialization.cpp @@ -21,9 +21,6 @@ #include <llvm/Support/ErrorHandling.h> #include <llvm/Support/TargetSelect.h> -#include <mcld/Support/TargetSelect.h> -#include <mcld/Support/TargetRegistry.h> - #include "bcc/Config/Config.h" #include "bcc/Support/Log.h" @@ -55,10 +52,6 @@ void bcc::init::Initialize() { LLVMInitializeARMTargetMC(); LLVMInitializeARMTargetInfo(); LLVMInitializeARMTarget(); - MCLDInitializeARMLDTargetInfo(); - MCLDInitializeARMLDTarget(); - MCLDInitializeARMLDBackend(); - MCLDInitializeARMDiagnosticLineInfo(); #endif #if defined(PROVIDE_MIPS_CODEGEN) @@ -69,10 +62,6 @@ void bcc::init::Initialize() { LLVMInitializeMipsTargetMC(); LLVMInitializeMipsTargetInfo(); LLVMInitializeMipsTarget(); - MCLDInitializeMipsLDTargetInfo(); - MCLDInitializeMipsLDTarget(); - MCLDInitializeMipsLDBackend(); - MCLDInitializeMipsDiagnosticLineInfo(); #endif #if defined(PROVIDE_X86_CODEGEN) @@ -83,10 +72,6 @@ void bcc::init::Initialize() { LLVMInitializeX86TargetMC(); LLVMInitializeX86TargetInfo(); LLVMInitializeX86Target(); - MCLDInitializeX86LDTargetInfo(); - MCLDInitializeX86LDTarget(); - MCLDInitializeX86LDBackend(); - MCLDInitializeX86DiagnosticLineInfo(); #endif is_initialized = true; diff --git a/lib/Support/LinkerConfig.cpp b/lib/Support/LinkerConfig.cpp deleted file mode 100644 index a4ede97..0000000 --- a/lib/Support/LinkerConfig.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bcc/Support/LinkerConfig.h" -#include "bcc/Support/Log.h" - -#include <llvm/Support/Signals.h> - -#include <mcld/LinkerConfig.h> -#include <mcld/MC/MCLDDirectory.h> -#include <mcld/MC/ZOption.h> -#include <mcld/LD/TextDiagnosticPrinter.h> -#include <mcld/Support/Path.h> -#include <mcld/Support/MsgHandling.h> -#include <mcld/Support/raw_ostream.h> - -using namespace bcc; - -LinkerConfig::LinkerConfig(const std::string &pTriple) - : mTriple(pTriple), mSOName(), mTarget(NULL), mLDConfig(NULL), - mDiagLineInfo(NULL), mDiagPrinter(NULL) { - - initializeTarget(); - initializeLDInfo(); - initializeDiagnostic(); -} - -LinkerConfig::~LinkerConfig() { - delete mLDConfig; - - if (mDiagPrinter->getNumErrors() != 0) { - // If here, the program failed ungracefully. Run the interrupt handlers to - // ensure any other cleanups (e.g., files that registered by - // RemoveFileOnSignal(...)) getting done before exit. - llvm::sys::RunInterruptHandlers(); - } - mDiagPrinter->finish(); - - delete mDiagLineInfo; - delete mDiagPrinter; -} - -bool LinkerConfig::initializeTarget() { - std::string error; - mTarget = mcld::TargetRegistry::lookupTarget(mTriple, error); - if (NULL != mTarget) { - return true; - } else { - ALOGE("Cannot initialize mcld::Target for given triple '%s'! (%s)\n", - mTriple.c_str(), error.c_str()); - return false; - } -} - -bool LinkerConfig::initializeLDInfo() { - if (NULL != mLDConfig) { - ALOGE("Cannot initialize mcld::MCLDInfo for given triple '%s!\n", - mTriple.c_str()); - return false; - } - - mLDConfig = new mcld::LinkerConfig(getTriple()); - mLDConfig->setCodeGenType(mcld::LinkerConfig::Exec); - - struct NameMap { - const char* from; - const char* to; - }; - - static const NameMap map[] = - { - {".text", ".text"}, - {".rodata", ".rodata"}, - {".data.rel.ro.local", ".data.rel.ro.local"}, - {".data.rel.ro", ".data.rel.ro"}, - {".data", ".data"}, - {".bss", ".bss"}, - {".tdata", ".tdata"}, - {".tbss", ".tbss"}, - {".init_array", ".init_array"}, - {".fini_array", ".fini_array"}, - // TODO: Support DT_INIT_ARRAY for all constructors? - {".ctors", ".ctors"}, - {".dtors", ".dtors"}, - // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2 - // sections would be handled differently. - {".sdata2", ".sdata"}, - {".sbss2", ".sbss"}, - {".sdata", ".sdata"}, - {".sbss", ".sbss"}, - {".lrodata", ".lrodata"}, - {".ldata", ".ldata"}, - {".lbss", ".lbss"}, - {".gcc_except_table", ".gcc_except_table"}, - {".gnu.linkonce.d.rel.ro.local", ".data.rel.ro.local"}, - {".gnu.linkonce.d.rel.ro", ".data.rel.ro"}, - {".gnu.linkonce.r", ".rodata"}, - {".gnu.linkonce.d", ".data"}, - {".gnu.linkonce.b", ".bss"}, - {".gnu.linkonce.sb2", ".sbss"}, - {".gnu.linkonce.sb", ".sbss"}, - {".gnu.linkonce.s2", ".sdata"}, - {".gnu.linkonce.s", ".sdata"}, - {".gnu.linkonce.wi", ".debug_info"}, - {".gnu.linkonce.td", ".tdata"}, - {".gnu.linkonce.tb", ".tbss"}, - {".gnu.linkonce.t", ".text"}, - {".gnu.linkonce.lr", ".lrodata"}, - {".gnu.linkonce.lb", ".lbss"}, - {".gnu.linkonce.l", ".ldata"}, - }; - - if (mLDConfig->codeGenType() != mcld::LinkerConfig::Object) { - const unsigned int map_size = (sizeof(map) / sizeof(map[0]) ); - for (unsigned int i = 0; i < map_size; ++i) { - bool exist = false; - mLDConfig->scripts().sectionMap().append(map[i].from, - map[i].to, - exist); - } - } - return true; -} - -bool LinkerConfig::initializeDiagnostic() { - // Set up MsgHandler. - mDiagPrinter = new mcld::TextDiagnosticPrinter(mcld::errs(), *mLDConfig); - - mcld::InitializeDiagnosticEngine(*mLDConfig, mDiagPrinter); - - mDiagLineInfo = mTarget->createDiagnosticLineInfo(*mTarget, mTriple); - - mcld::getDiagnosticEngine().setLineInfo(*mDiagLineInfo); - return true; -} - -bool LinkerConfig::isShared() const { - return (mcld::LinkerConfig::DynObj == mLDConfig->codeGenType()); -} - -void LinkerConfig::setShared(bool pEnable) { - if (pEnable) - mLDConfig->setCodeGenType(mcld::LinkerConfig::DynObj); - else - mLDConfig->setCodeGenType(mcld::LinkerConfig::Exec); - return; -} - -void LinkerConfig::setBsymbolic(bool pEnable) { - mLDConfig->options().setBsymbolic(pEnable); - return; -} - -void LinkerConfig::setDefineCommon(bool pEnable) { - mLDConfig->options().setDefineCommon(pEnable); - return; -} - -void LinkerConfig::setSOName(const std::string &pSOName) { - mLDConfig->options().setSOName(pSOName); - return; -} - -void LinkerConfig::setDyld(const std::string &pDyld) { - mLDConfig->options().setDyld(pDyld); - return; -} - -void LinkerConfig::setSysRoot(const std::string &pSysRoot) { - mLDConfig->options().setSysroot(mcld::sys::fs::Path(pSysRoot)); - return; -} - -void LinkerConfig::setZOption(unsigned int pOptions) { - mcld::ZOption option; - if (pOptions & kCombReloc) { - option.setKind(mcld::ZOption::CombReloc); - mLDConfig->options().addZOption(option); - } - else { - option.setKind(mcld::ZOption::NoCombReloc); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kDefs) { - option.setKind(mcld::ZOption::Defs); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kExecStack) { - option.setKind(mcld::ZOption::ExecStack); - mLDConfig->options().addZOption(option); - } - else { - option.setKind(mcld::ZOption::NoExecStack); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kInitFirst) { - option.setKind(mcld::ZOption::InitFirst); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kInterPose) { - option.setKind(mcld::ZOption::InterPose); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kLoadFltr) { - option.setKind(mcld::ZOption::LoadFltr); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kMulDefs) { - option.setKind(mcld::ZOption::MulDefs); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kNoCopyReloc) { - option.setKind(mcld::ZOption::NoCopyReloc); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kNoDefaultLib) { - option.setKind(mcld::ZOption::NoDefaultLib); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kNoDelete) { - option.setKind(mcld::ZOption::NoDelete); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kNoDLOpen) { - option.setKind(mcld::ZOption::NoDLOpen); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kNoDump) { - option.setKind(mcld::ZOption::NoDump); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kRelro) { - option.setKind(mcld::ZOption::Relro); - mLDConfig->options().addZOption(option); - } - else { - option.setKind(mcld::ZOption::NoRelro); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kLazy) { - option.setKind(mcld::ZOption::Lazy); - mLDConfig->options().addZOption(option); - } - else { - option.setKind(mcld::ZOption::Now); - mLDConfig->options().addZOption(option); - } - - if (pOptions & kOrigin) { - option.setKind(mcld::ZOption::Origin); - mLDConfig->options().addZOption(option); - } -} - -void LinkerConfig::addWrap(const std::string &pWrapSymbol) { - bool exist = false; - - // Add wname -> __wrap_wname. - mcld::StringEntry<llvm::StringRef>* to_wrap = - mLDConfig->scripts().renameMap().insert(pWrapSymbol, exist); - - std::string to_wrap_str = "__wrap_" + pWrapSymbol; - to_wrap->setValue(to_wrap_str); - - if (exist) { - mcld::warning(mcld::diag::rewrap) << pWrapSymbol << to_wrap_str; - } - - // Add __real_wname -> wname. - std::string from_real_str = "__real_" + pWrapSymbol; - mcld::StringEntry<llvm::StringRef>* from_real = - mLDConfig->scripts().renameMap().insert(from_real_str, exist); - from_real->setValue(pWrapSymbol); - - if (exist) { - mcld::warning(mcld::diag::rewrap) << pWrapSymbol << from_real_str; - } - - return; -} - -void LinkerConfig::addPortable(const std::string &pPortableSymbol) { - bool exist = false; - - // Add pname -> pname_portable. - mcld::StringEntry<llvm::StringRef>* to_port = - mLDConfig->scripts().renameMap().insert(pPortableSymbol, exist); - - std::string to_port_str = pPortableSymbol + "_portable"; - to_port->setValue(to_port_str); - - if (exist) { - mcld::warning(mcld::diag::rewrap) << pPortableSymbol << to_port_str; -} - - // Add __real_pname -> pname. - std::string from_real_str = "__real_" + pPortableSymbol; - mcld::StringEntry<llvm::StringRef>* from_real = - mLDConfig->scripts().renameMap().insert(from_real_str, exist); - - from_real->setValue(pPortableSymbol); - - if (exist) { - mcld::warning(mcld::diag::rewrap) << pPortableSymbol << from_real_str; - } - - return; -} - -void LinkerConfig::addSearchDir(const std::string &pDirPath) { - // SearchDirs will remove the created MCLDDirectory. - if (!mLDConfig->options().directories().insert(pDirPath)) { - mcld::warning(mcld::diag::warn_cannot_open_search_dir) << pDirPath; - } -} diff --git a/lib/Support/TargetLinkerConfigs.cpp b/lib/Support/TargetLinkerConfigs.cpp deleted file mode 100644 index d7e6163..0000000 --- a/lib/Support/TargetLinkerConfigs.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "bcc/Config/Config.h" -#include "bcc/Support/TargetLinkerConfigs.h" - -#include <mcld/TargetOptions.h> -#include <mcld/MC/InputFactory.h> -#include <mcld/Fragment/Relocation.h> - -using namespace bcc; - -#ifdef TARGET_BUILD -static const char* gDefaultDyld = "/system/bin/linker"; -static const char* gDefaultSysroot = "/system"; -#else -static const char* gDefaultDyld = "/usr/lib/ld.so.1"; -static const char* gDefaultSysroot = "/"; -#endif - -//===----------------------------------------------------------------------===// -// ARM -//===----------------------------------------------------------------------===// -#if defined(PROVIDE_ARM_CODEGEN) -ARMLinkerConfig::ARMLinkerConfig() : LinkerConfig(DEFAULT_ARM_TRIPLE_STRING) { - - // set up target-dependent options - getLDConfig()->targets().setEndian(mcld::TargetOptions::Little); - getLDConfig()->targets().setBitClass(32); - - // set up target-dependent constraints of attributes - getLDConfig()->attribute().constraint().enableWholeArchive(); - getLDConfig()->attribute().constraint().disableAsNeeded(); - getLDConfig()->attribute().constraint().setSharedSystem(); - - // set up the predefined attributes - getLDConfig()->attribute().predefined().unsetWholeArchive(); - getLDConfig()->attribute().predefined().setDynamic(); - - // set up target dependent options - if (getLDConfig()->options().sysroot().empty()) { - getLDConfig()->options().setSysroot(gDefaultSysroot); - } - - if (!getLDConfig()->options().hasDyld()) { - getLDConfig()->options().setDyld(gDefaultDyld); - } - - // set up section map - if (getLDConfig()->codeGenType() != mcld::LinkerConfig::Object) { - bool exist = false; - getLDConfig()->scripts().sectionMap().append(".ARM.exidx", ".ARM.exidx", exist); - getLDConfig()->scripts().sectionMap().append(".ARM.extab", ".ARM.extab", exist); - getLDConfig()->scripts().sectionMap().append(".ARM.attributes", ".ARM.attributes", exist); - } - - // set up relocation factory - mcld::Relocation::SetUp(*getLDConfig()); -} -#endif // defined(PROVIDE_ARM_CODEGEN) - -//===----------------------------------------------------------------------===// -// Mips -//===----------------------------------------------------------------------===// -#if defined(PROVIDE_MIPS_CODEGEN) -MipsLinkerConfig::MipsLinkerConfig() - : LinkerConfig(DEFAULT_MIPS_TRIPLE_STRING) { - - // set up target-dependent options - getLDConfig()->targets().setEndian(mcld::TargetOptions::Little); - getLDConfig()->targets().setBitClass(32); - - // set up target-dependent constraints of attibutes - getLDConfig()->attribute().constraint().enableWholeArchive(); - getLDConfig()->attribute().constraint().disableAsNeeded(); - getLDConfig()->attribute().constraint().setSharedSystem(); - - // set up the predefined attributes - getLDConfig()->attribute().predefined().unsetWholeArchive(); - getLDConfig()->attribute().predefined().setDynamic(); - - // set up target dependent options - if (getLDConfig()->options().sysroot().empty()) { - getLDConfig()->options().setSysroot(gDefaultSysroot); - } - - if (!getLDConfig()->options().hasDyld()) { - getLDConfig()->options().setDyld(gDefaultDyld); - } - - // set up relocation factory - mcld::Relocation::SetUp(*getLDConfig()); -} -#endif // defined(PROVIDE_MIPS_CODEGEN) - -//===----------------------------------------------------------------------===// -// X86 and X86_64 -//===----------------------------------------------------------------------===// -#if defined(PROVIDE_X86_CODEGEN) -X86FamilyLinkerConfigBase::X86FamilyLinkerConfigBase(const std::string& pTriple) - : LinkerConfig(pTriple) { - // set up target-dependent options - getLDConfig()->targets().setEndian(mcld::TargetOptions::Little); - getLDConfig()->targets().setBitClass(32); - - // set up target-dependent constraints of attibutes - getLDConfig()->attribute().constraint().enableWholeArchive(); - getLDConfig()->attribute().constraint().disableAsNeeded(); - getLDConfig()->attribute().constraint().setSharedSystem(); - - // set up the predefined attributes - getLDConfig()->attribute().predefined().unsetWholeArchive(); - getLDConfig()->attribute().predefined().setDynamic(); - - // set up target dependent options - if (getLDConfig()->options().sysroot().empty()) { - getLDConfig()->options().setSysroot(gDefaultSysroot); - } - - if (!getLDConfig()->options().hasDyld()) { - getLDConfig()->options().setDyld(gDefaultDyld); - } - - // set up relocation factory - mcld::Relocation::SetUp(*getLDConfig()); -} - -X86_32LinkerConfig::X86_32LinkerConfig() - : X86FamilyLinkerConfigBase(DEFAULT_X86_TRIPLE_STRING) { -} - -X86_64LinkerConfig::X86_64LinkerConfig() - : X86FamilyLinkerConfigBase(DEFAULT_X86_64_TRIPLE_STRING) { -} -#endif // defined(PROVIDE_X86_CODEGEN) - -#if !defined(TARGET_BUILD) -//===----------------------------------------------------------------------===// -// General -//===----------------------------------------------------------------------===// -GeneralLinkerConfig::GeneralLinkerConfig(const std::string& pTriple) - : LinkerConfig(pTriple) { - - // set up target-dependent options - getLDConfig()->targets().setEndian(mcld::TargetOptions::Little); - getLDConfig()->targets().setBitClass(32); - - // set up target-dependent constraints of attributes - getLDConfig()->attribute().constraint().enableWholeArchive(); - getLDConfig()->attribute().constraint().disableAsNeeded(); - getLDConfig()->attribute().constraint().setSharedSystem(); - - // set up the predefined attributes - getLDConfig()->attribute().predefined().unsetWholeArchive(); - getLDConfig()->attribute().predefined().setDynamic(); - - // set up section map - if (llvm::Triple::arm == getLDConfig()->targets().triple().getArch() && - getLDConfig()->codeGenType() != mcld::LinkerConfig::Object) { - bool exist = false; - getLDConfig()->scripts().sectionMap().append(".ARM.exidx", ".ARM.exidx", exist); - getLDConfig()->scripts().sectionMap().append(".ARM.extab", ".ARM.extab", exist); - getLDConfig()->scripts().sectionMap().append(".ARM.attributes", ".ARM.attributes", exist); - } - - // set up relocation factory - mcld::Relocation::SetUp(*getLDConfig()); -} -#endif // defined(TARGET_BUILD) diff --git a/libbcc-device-build.mk b/libbcc-device-build.mk index aead9c1..48fa35f 100644 --- a/libbcc-device-build.mk +++ b/libbcc-device-build.mk @@ -64,5 +64,9 @@ else endif LOCAL_C_INCLUDES := \ + bionic \ + external/stlport/stlport \ $(LIBBCC_ROOT_PATH)/include \ + $(LLVM_ROOT_PATH)/include \ + $(LLVM_ROOT_PATH)/device/include \ $(LOCAL_C_INCLUDES) diff --git a/libbcc-host-build.mk b/libbcc-host-build.mk index 4192f87..0b272e7 100644 --- a/libbcc-host-build.mk +++ b/libbcc-host-build.mk @@ -29,6 +29,8 @@ endif LOCAL_C_INCLUDES := \ $(LIBBCC_ROOT_PATH)/include \ + $(LLVM_ROOT_PATH)/include \ + $(LLVM_ROOT_PATH)/host/include \ $(LOCAL_C_INCLUDES) LOCAL_IS_HOST_MODULE := true @@ -43,8 +43,3 @@ include $(LIBBCC_ROOT_PATH)/libbcc-config.mk # Related Makefile Paths of LLVM #===================================================================== include $(LLVM_ROOT_PATH)/llvm.mk - -#===================================================================== -# Related Makefile Paths of MCLinker -#===================================================================== -include $(MCLD_ROOT_PATH)/mcld.mk diff --git a/tools/mcld/Android.mk b/tools/mcld/Android.mk deleted file mode 100644 index d2e5cea..0000000 --- a/tools/mcld/Android.mk +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (C) 2010-2012 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -LOCAL_PATH := $(call my-dir) - -# Executable for host -# ======================================================== -include $(CLEAR_VARS) - -LOCAL_MODULE := mcld -LOCAL_MODULE_CLASS := EXECUTABLES - -LOCAL_SRC_FILES := Main.cpp - -LOCAL_SHARED_LIBRARIES := \ - libbcc \ - libbcinfo \ - libLLVM - -LOCAL_LDLIBS = -ldl - -include $(LIBBCC_HOST_BUILD_MK) -include $(LIBBCC_GEN_CONFIG_MK) -include $(MCLD_HOST_BUILD_MK) -#include $(LLVM_HOST_BUILD_MK) -include $(BUILD_HOST_EXECUTABLE) - -# Executable for target -# ======================================================== -include $(CLEAR_VARS) - -LOCAL_MODULE := mcld -LOCAL_MODULE_CLASS := EXECUTABLES - -LOCAL_SRC_FILES := Main.cpp - -LOCAL_SHARED_LIBRARIES := libdl libstlport libbcc libbcinfo libLLVM - -include external/stlport/libstlport.mk -include $(LIBBCC_DEVICE_BUILD_MK) -include $(LIBBCC_GEN_CONFIG_MK) -include $(MCLD_DEVICE_BUILD_MK) -#include $(LLVM_DEVICE_BUILD_MK) -include $(BUILD_EXECUTABLE) diff --git a/tools/mcld/Main.cpp b/tools/mcld/Main.cpp deleted file mode 100644 index ac4772e..0000000 --- a/tools/mcld/Main.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright 2012, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <string> - -#include <llvm/ADT/SmallString.h> -#include <llvm/Support/CommandLine.h> -#include <llvm/Support/FileSystem.h> -#include <llvm/Support/Path.h> -#include <llvm/Support/raw_ostream.h> -#include <llvm/Support/system_error.h> - -#include <mcld/Config/Config.h> - -#include <bcc/Config/Config.h> -#include <bcc/Support/LinkerConfig.h> -#include <bcc/Support/Initialization.h> -#include <bcc/Support/TargetLinkerConfigs.h> -#include <bcc/Linker.h> - -using namespace bcc; - -//===----------------------------------------------------------------------===// -// Compiler Options -//===----------------------------------------------------------------------===// -#ifdef TARGET_BUILD -static const std::string OptTargetTripe(DEFAULT_TARGET_TRIPLE_STRING); -#else -static llvm::cl::opt<std::string> -OptTargetTriple("mtriple", - llvm::cl::desc("Specify the target triple (default: " - DEFAULT_TARGET_TRIPLE_STRING ")"), - llvm::cl::init(DEFAULT_TARGET_TRIPLE_STRING), - llvm::cl::value_desc("triple")); - -static llvm::cl::alias OptTargetTripleC("C", llvm::cl::NotHidden, - llvm::cl::desc("Alias for -mtriple"), - llvm::cl::aliasopt(OptTargetTriple)); -#endif - -//===----------------------------------------------------------------------===// -// Command Line Options -// There are four kinds of command line options: -// 1. input, (may be a file, such as -m and /tmp/XXXX.o.) -// 2. scripting options, (represent a subset of link scripting language, such -// as --defsym.) -// 3. and general options. (the rest of options) -//===----------------------------------------------------------------------===// -// General Options -//===----------------------------------------------------------------------===// -static llvm::cl::opt<std::string> -OptOutputFilename("o", - llvm::cl::desc("Output filename"), - llvm::cl::value_desc("filename")); - -static llvm::cl::opt<std::string> -OptSysRoot("sysroot", llvm::cl::desc("Use directory as the location of the " - "sysroot, overriding the configure-time " - "default."), - llvm::cl::value_desc("directory"), - llvm::cl::ValueRequired); - -static llvm::cl::list<std::string> -OptSearchDirList("L", - llvm::cl::ZeroOrMore, - llvm::cl::desc("Add path searchdir to the list of paths that " - "mcld will search for archive libraries and " - "mcld control scripts."), - llvm::cl::value_desc("searchdir"), - llvm::cl::Prefix); - -static llvm::cl::opt<std::string> -OptSOName("soname", - llvm::cl::desc("Set internal name of shared library"), - llvm::cl::value_desc("name")); - - -static llvm::cl::opt<bool> -OptShared("shared", - llvm::cl::desc("Create a shared library."), - llvm::cl::init(false)); - -static llvm::cl::opt<bool> -OptBsymbolic("Bsymbolic", - llvm::cl::desc("Bind references within the shared library."), - llvm::cl::init(true)); - -static llvm::cl::opt<std::string> -OptDyld("dynamic-linker", - llvm::cl::desc("Set the name of the dynamic linker."), - llvm::cl::value_desc("Program")); - -static llvm::cl::opt<bool> -OptRelocatable("relocatable", - llvm::cl::desc("Generate relocatable output"), - llvm::cl::init(false)); - -static llvm::cl::alias -OptRelocatableAlias("r", - llvm::cl::desc("alias for --relocatable"), - llvm::cl::aliasopt(OptRelocatable)); - -static llvm::cl::opt<bool> -OptDefineCommon("d", - llvm::cl::ZeroOrMore, - llvm::cl::desc("Define common symbol"), - llvm::cl::init(false)); - -static llvm::cl::alias -OptDefineCommonAlias1("dc", - llvm::cl::desc("alias for -d"), - llvm::cl::aliasopt(OptDefineCommon)); - -static llvm::cl::alias -OptDefineCommonAlias2("dp", - llvm::cl::desc("alias for -d"), - llvm::cl::aliasopt(OptDefineCommon)); - - -//===----------------------------------------------------------------------===// -// Inputs -//===----------------------------------------------------------------------===// -static llvm::cl::list<std::string> -OptInputObjectFiles(llvm::cl::Positional, - llvm::cl::desc("[input object files]"), - llvm::cl::OneOrMore); - -static llvm::cl::list<std::string> -OptNameSpecList("l", - llvm::cl::ZeroOrMore, - llvm::cl::desc("Add the archive or object file specified by " - "namespec to the list of files to link."), - llvm::cl::value_desc("namespec"), - llvm::cl::Prefix); - -//===----------------------------------------------------------------------===// -// Scripting Options -//===----------------------------------------------------------------------===// -static llvm::cl::list<std::string> -OptWrapList("wrap", - llvm::cl::ZeroOrMore, - llvm::cl::desc("Use a wrap function fo symbol."), - llvm::cl::value_desc("symbol")); - -static llvm::cl::list<std::string> -OptPortableList("portable", - llvm::cl::ZeroOrMore, - llvm::cl::desc("Use a portable function to symbol."), - llvm::cl::value_desc("symbol")); - -//===----------------------------------------------------------------------===// -// Helper Functions -//===----------------------------------------------------------------------===// -// Override "mcld -version" -static void MCLDVersionPrinter() { - llvm::raw_ostream &os = llvm::outs(); - os << "mcld (The MCLinker Project, http://mclinker.googlecode.com/):\n" - << " version: " MCLD_VERSION "\n" - << " Default target: " << DEFAULT_TARGET_TRIPLE_STRING << "\n"; - - os << "\n"; - - os << "LLVM (http://llvm.org/):\n"; - - return; -} - -#define DEFAULT_OUTPUT_PATH "a.out" -static inline -std::string DetermineOutputFilename(const std::string &pOutputPath) { - if (!pOutputPath.empty()) { - return pOutputPath; - } - - // User does't specify the value to -o - if (OptInputObjectFiles.size() > 1) { - llvm::errs() << "Use " DEFAULT_OUTPUT_PATH " for output file!\n"; - return DEFAULT_OUTPUT_PATH; - } - - // There's only one input file - const std::string &input_path = OptInputObjectFiles[0]; - llvm::SmallString<200> output_path(input_path); - - llvm::error_code err = llvm::sys::fs::make_absolute(output_path); - if (llvm::errc::success != err) { - llvm::errs() << "Failed to determine the absolute path of `" << input_path - << "'! (detail: " << err.message() << ")\n"; - return ""; - } - - llvm::sys::path::remove_filename(output_path); - llvm::sys::path::append(output_path, "a.out"); - - return output_path.c_str(); -} - -static inline -bool ConfigLinker(Linker &pLinker, const std::string &pOutputFilename) { - LinkerConfig* config = NULL; - -#ifdef TARGET_BUILD - config = new (std::nothrow) DefaultLinkerConfig(); -#else - config = new (std::nothrow) GeneralLinkerConfig(OptTargetTriple); -#endif - if (config == NULL) { - llvm::errs() << "Out of memory when create the linker configuration!\n"; - return false; - } - - // Setup the configuration accroding to the command line options. - - // 1. Set up soname. - if (!OptSOName.empty()) { - config->setSOName(OptSOName); - } else { - config->setSOName(pOutputFilename); - } - - // 2. If given, set up sysroot. - if (!OptSysRoot.empty()) { - config->setSysRoot(OptSysRoot); - } - - // 3. If given, set up dynamic linker path. - if (!OptDyld.empty()) { - config->setDyld(OptDyld); - } - - // 4. If given, set up wrapped symbols. - llvm::cl::list<std::string>::iterator wrap, wrap_end = OptWrapList.end(); - for (wrap = OptWrapList.begin(); wrap != wrap_end; ++wrap) { - config->addWrap(*wrap); - } - - // 5. If given, set up portable symbols. - llvm::cl::list<std::string>::iterator portable, portable_end = OptPortableList.end(); - for (portable = OptPortableList.begin(); portable != portable_end; ++portable) { - config->addPortable(*portable); - } - - // 6. if given, set up search directories. - llvm::cl::list<std::string>::iterator sdir, sdir_end = OptSearchDirList.end(); - for (sdir = OptSearchDirList.begin(); sdir != sdir_end; ++sdir) { - config->addSearchDir(*sdir); - } - - // set up default search directories - config->addSearchDir("=/lib"); - config->addSearchDir("=/usr/lib"); - - // 7. Set up output's type. - config->setShared(OptShared); - - // 8. Set up -Bsymbolic. - config->setBsymbolic(OptBsymbolic); - - // 9. Set up -d (define common symbols) - config->setDefineCommon(OptDefineCommon); - - Linker::ErrorCode result = pLinker.config(*config); - if (Linker::kSuccess != result) { - llvm::errs() << "Failed to configure the linker! (detail: " - << Linker::GetErrorString(result) << ")\n"; - return false; - } - - return true; -} - -static inline -bool PrepareInputOutput(Linker &pLinker, const std::string &pOutputPath) { - // ----- Set output ----- // - - // FIXME: Current MCLinker requires one to set up output before inputs. The - // constraint will be relaxed in the furture. - Linker::ErrorCode result = pLinker.setOutput(pOutputPath); - - if (Linker::kSuccess != result) { - llvm::errs() << "Failed to open the output file! (detail: " - << pOutputPath << ": " - << Linker::GetErrorString(result) << ")\n"; - return false; - } - - // ----- Set inputs ----- // - llvm::cl::list<std::string>::iterator file_it = OptInputObjectFiles.begin(); - llvm::cl::list<std::string>::iterator lib_it = OptNameSpecList.begin(); - - llvm::cl::list<std::string>::iterator file_begin = OptInputObjectFiles.begin(); - llvm::cl::list<std::string>::iterator lib_begin = OptNameSpecList.begin(); - llvm::cl::list<std::string>::iterator file_end = OptInputObjectFiles.end(); - llvm::cl::list<std::string>::iterator lib_end = OptNameSpecList.end(); - - unsigned lib_pos = 0, file_pos = 0; - while (true) { - if (lib_it != lib_end) { - lib_pos = OptNameSpecList.getPosition(lib_it - lib_begin); - } else { - lib_pos = 0; - } - - if (file_it != file_end) { - file_pos = OptInputObjectFiles.getPosition(file_it - file_begin); - } else { - file_pos = 0; - } - - if ((file_pos != 0) && ((lib_pos == 0) || (file_pos < lib_pos))) { - result = pLinker.addObject(*file_it); - if (Linker::kSuccess != result) { - llvm::errs() << "Failed to open the input file! (detail: " << *file_it - << ": " << Linker::GetErrorString(result) << ")\n"; - return false; - } - ++file_it; - } else if ((lib_pos != 0) && ((file_pos == 0) || (lib_pos < file_pos))) { - result = pLinker.addNameSpec(*lib_it); - if (Linker::kSuccess != result) { - llvm::errs() << "Failed to open the namespec! (detail: " << *lib_it - << ": " << Linker::GetErrorString(result) << ")\n"; - return false; - } - ++lib_it; - } else { - break; // we're done with the list - } - } - - return true; -} - -static inline bool LinkFiles(Linker &pLinker) { - Linker::ErrorCode result = pLinker.link(); - if (Linker::kSuccess != result) { - llvm::errs() << "Failed to linking! (detail: " - << Linker::GetErrorString(result) << "\n"; - return false; - } - return true; -} - -int main(int argc, char** argv) { - llvm::cl::SetVersionPrinter(MCLDVersionPrinter); - llvm::cl::ParseCommandLineOptions(argc, argv); - init::Initialize(); - - std::string OutputFilename = DetermineOutputFilename(OptOutputFilename); - if (OutputFilename.empty()) { - return EXIT_FAILURE; - } - - Linker linker; - if (!ConfigLinker(linker, OutputFilename)) { - return EXIT_FAILURE; - } - - if (!PrepareInputOutput(linker, OutputFilename)) { - return EXIT_FAILURE; - } - - if (!LinkFiles(linker)) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - |