mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-31 14:15:12 +00:00
Fix MSVC incompatibilities.
llvm-svn: 152389
This commit is contained in:
parent
b5ef4df359
commit
e753cbc685
@ -64,13 +64,15 @@ endif()
|
||||
# lld now requires C++11 to build
|
||||
#
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("-std=c++0x" SUPPORTS_CXX11_FLAG)
|
||||
if( SUPPORTS_CXX11_FLAG )
|
||||
message(STATUS "Building with -std=c++0x")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
|
||||
else( SUPPORTS_CXX11_FLAG )
|
||||
message(WARNING "-std=c++0x not supported.")
|
||||
if (NOT MSVC)
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("-std=c++0x" SUPPORTS_CXX11_FLAG)
|
||||
if( SUPPORTS_CXX11_FLAG )
|
||||
message(STATUS "Building with -std=c++0x")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
|
||||
else( SUPPORTS_CXX11_FLAG )
|
||||
message(WARNING "-std=c++0x not supported.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
|
@ -188,11 +188,11 @@ protected:
|
||||
class atom_collection_vector : public atom_collection<T> {
|
||||
public:
|
||||
virtual atom_iterator<T> begin() const {
|
||||
return atom_iterator<T>(*this, reinterpret_cast<const void*>(&_atoms[0]));
|
||||
return atom_iterator<T>(*this, reinterpret_cast<const void*>(_atoms.data()));
|
||||
}
|
||||
virtual atom_iterator<T> end() const{
|
||||
return atom_iterator<T>(*this, reinterpret_cast<const void*>
|
||||
(&_atoms[_atoms.size()]));
|
||||
(_atoms.data() + _atoms.size()));
|
||||
}
|
||||
virtual const T* deref(const void* it) const {
|
||||
return *reinterpret_cast<const T* const*>(it);
|
||||
|
@ -335,8 +335,7 @@ private:
|
||||
}
|
||||
// first use of this library name
|
||||
uint32_t result = this->getNameOffset(name);
|
||||
_sharedLibraryNames.push_back(
|
||||
std::make_pair<llvm::StringRef, uint32_t>(name, result));
|
||||
_sharedLibraryNames.push_back(std::make_pair(name, result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -390,8 +389,7 @@ private:
|
||||
}
|
||||
// first use of this section name
|
||||
uint32_t result = this->getNameOffset(name);
|
||||
_sectionNames.push_back(
|
||||
std::make_pair<llvm::StringRef, uint32_t>(name, result));
|
||||
_sectionNames.push_back(std::make_pair(name, result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "lld/Platform/Platform.h"
|
||||
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
@ -934,7 +935,9 @@ llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
|
||||
haveAtom = true;
|
||||
}
|
||||
else if (strcmp(entry->key, KeyValues::valueKeyword) == 0) {
|
||||
llvm::StringRef(entry->value).getAsInteger(0, atomState._value);
|
||||
llvm::APInt Val;
|
||||
llvm::StringRef(entry->value).getAsInteger(0, Val);
|
||||
atomState._value = Val.getZExtValue();
|
||||
haveAtom = true;
|
||||
}
|
||||
else {
|
||||
@ -953,8 +956,9 @@ llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
|
||||
haveFixup = true;
|
||||
}
|
||||
else if (strcmp(entry->key, KeyValues::fixupsOffsetKeyword) == 0) {
|
||||
llvm::StringRef(entry->value).getAsInteger(0,
|
||||
atomState._ref._offsetInAtom);
|
||||
llvm::APInt Val;
|
||||
llvm::StringRef(entry->value).getAsInteger(0, Val);
|
||||
atomState._ref._offsetInAtom = Val.getZExtValue();
|
||||
haveFixup = true;
|
||||
}
|
||||
else if (strcmp(entry->key, KeyValues::fixupsTargetKeyword) == 0) {
|
||||
@ -962,8 +966,19 @@ llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
|
||||
haveFixup = true;
|
||||
}
|
||||
else if (strcmp(entry->key, KeyValues::fixupsAddendKeyword) == 0) {
|
||||
llvm::StringRef(entry->value).getAsInteger(0,
|
||||
atomState._ref._addend);
|
||||
llvm::APInt Val;
|
||||
// HACK: getAsInteger for APInt doesn't handle negative values
|
||||
// the same as other getAsInteger functions. And getAsInteger
|
||||
// doesn't work on all platforms for {,u}int64_t. So manually
|
||||
// handle this until getAsInteger is fixed.
|
||||
bool IsNeg = false;
|
||||
llvm::StringRef Addend(entry->value);
|
||||
if (Addend.find('-') == 0) {
|
||||
IsNeg = true;
|
||||
Addend = Addend.substr(1);
|
||||
}
|
||||
Addend.getAsInteger(0, Val);
|
||||
atomState._ref._addend = Val.getSExtValue() * (IsNeg ? -1 : 1);
|
||||
haveFixup = true;
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,13 @@
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
|
||||
#include <vector>
|
||||
@ -62,9 +65,10 @@ public:
|
||||
const Reference* ref = *rit;
|
||||
// create refname for any unnamed reference target
|
||||
if ( ref->target()->name().empty() ) {
|
||||
char* buffer;
|
||||
asprintf(&buffer, "L%03d", _unnamedCounter++);
|
||||
_refNames[ref->target()] = buffer;
|
||||
std::string Storage;
|
||||
llvm::raw_string_ostream Buffer(Storage);
|
||||
Buffer << llvm::format("L%03d", _unnamedCounter++);
|
||||
_refNames[ref->target()] = Buffer.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,15 +96,16 @@ public:
|
||||
NameToAtom::iterator pos = _nameMap.find(atom.name());
|
||||
if ( pos != _nameMap.end() ) {
|
||||
// Found name collision, give each a unique ref-name.
|
||||
char* buffer;
|
||||
asprintf(&buffer, "%s.%03d", atom.name().data(), ++_collisionCount);
|
||||
_refNames[&atom] = buffer;
|
||||
std::string Storage;
|
||||
llvm::raw_string_ostream Buffer(Storage);
|
||||
Buffer << atom.name() << llvm::format(".%03d", ++_collisionCount);
|
||||
_refNames[&atom] = Buffer.str();
|
||||
const Atom* prevAtom = pos->second;
|
||||
AtomToRefName::iterator pos2 = _refNames.find(prevAtom);
|
||||
if ( pos2 == _refNames.end() ) {
|
||||
// only create ref-name for previous if none already created
|
||||
asprintf(&buffer, "%s.%03d", prevAtom->name().data(), ++_collisionCount);
|
||||
_refNames[prevAtom] = buffer;
|
||||
Buffer << prevAtom->name() << llvm::format(".%03d", ++_collisionCount);
|
||||
_refNames[prevAtom] = Buffer.str();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -113,21 +118,13 @@ public:
|
||||
return _refNames.count(atom);
|
||||
}
|
||||
|
||||
const char* refName(const Atom* atom) {
|
||||
llvm::StringRef refName(const Atom* atom) {
|
||||
return _refNames.find(atom)->second;
|
||||
}
|
||||
|
||||
private:
|
||||
struct MyMappingInfo {
|
||||
static llvm::StringRef getEmptyKey() { return llvm::StringRef(); }
|
||||
static llvm::StringRef getTombstoneKey() { return llvm::StringRef(" ", 0); }
|
||||
static unsigned getHashValue(llvm::StringRef const val) {
|
||||
return llvm::HashString(val); }
|
||||
static bool isEqual(llvm::StringRef const lhs,
|
||||
llvm::StringRef const rhs) { return lhs.equals(rhs); }
|
||||
};
|
||||
typedef llvm::DenseMap<llvm::StringRef, const Atom*, MyMappingInfo> NameToAtom;
|
||||
typedef llvm::DenseMap<const Atom*, const char*> AtomToRefName;
|
||||
typedef llvm::StringMap<const Atom*> NameToAtom;
|
||||
typedef llvm::DenseMap<const Atom*, std::string> AtomToRefName;
|
||||
|
||||
unsigned int _collisionCount;
|
||||
unsigned int _unnamedCounter;
|
||||
|
@ -1,9 +1,11 @@
|
||||
# RUN: lld-core %s 2>&1 | grep "duplicate symbol"
|
||||
# RUN: lld-core %s 2>&1 | FileCheck %s
|
||||
|
||||
#
|
||||
# Test that multiple definitions cause an error
|
||||
#
|
||||
|
||||
# CHECK: duplicate symbol
|
||||
|
||||
---
|
||||
atoms:
|
||||
- name: _foo
|
||||
@ -17,4 +19,3 @@ atoms:
|
||||
scope: global
|
||||
type: data
|
||||
...
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user