Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to LLVM 9 #19

Merged
merged 10 commits into from
Jul 11, 2019
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void AsanCheckIncompatibleRT() {
// the functions in dynamic ASan runtime instead of the functions in
// system libraries, causing crashes later in ASan initialization.
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
char filename[PATH_MAX];
char filename[4096];
MemoryMappedSegment segment(filename, sizeof(filename));
while (proc_maps.Next(&segment)) {
if (IsDynamicRTName(segment.filename)) {
Expand Down
6 changes: 1 addition & 5 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,8 @@ u32 GetNumberOfCPUs() {
}
internal_close(fd);
return n_cpus;
#elif SANITIZER_SOLARIS
return sysconf(_SC_NPROCESSORS_ONLN);
#else
cpu_set_t CPUs;
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
return CPU_COUNT(&CPUs);
return sysconf(_SC_NPROCESSORS_ONLN);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ typedef struct user_fpregs elf_fpregset_t;
#endif

#if SANITIZER_LINUX && !SANITIZER_ANDROID
#include <stdio.h>
#include <glob.h>
#include <obstack.h>
#include <mqueue.h>
Expand Down Expand Up @@ -1010,9 +1011,9 @@ CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
#endif

#if SANITIZER_LINUX && (__ANDROID_API__ >= 21 || __GLIBC_PREREQ (2, 14))
CHECK_TYPE_SIZE(mmsghdr);
CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr);
CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);
// CHECK_TYPE_SIZE(mmsghdr);
// CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr);
// CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);
#endif

COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ bool ShouldMockFailureToOpen(const char *path) {
}

#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_GO
# ifndef O_CLOEXEC
# define O_CLOEXEC 0
# endif
int GetNamedMappingFd(const char *name, uptr size, int *flags) {
if (!common_flags()->decorate_proc_maps || !name)
return -1;
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/lib/xray/xray_x86_64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ retryingReadSome(int Fd, char *Begin, char *End) XRAY_NEVER_INSTRUMENT {
return std::make_pair(TotalBytesRead, true);
}

#ifndef O_CLOEXEC
# define O_CLOEXEC 0
#endif
static bool readValueFromFile(const char *Filename,
long long *Value) XRAY_NEVER_INSTRUMENT {
int Fd = open(Filename, O_RDONLY | O_CLOEXEC);
Expand Down
13 changes: 13 additions & 0 deletions lld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
)
endif()

if (MSVC)
FOREACH(flag
CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT)
if (MSVC)
STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}")
SET("${flag}" "${${flag}}")
endif (MSVC)
ENDFOREACH()
endif()

add_subdirectory(Common)
add_subdirectory(lib)
add_subdirectory(tools/lld)
Expand Down
27 changes: 14 additions & 13 deletions llvm/cmake/modules/CheckAtomic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ else()
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
endif()

# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
if(HAVE_CXX_LIBATOMICS64)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
message(FATAL_ERROR "Host compiler must support std::atomic!")
endif()
else()
message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
endif()
endif()
# RUST-SPECIFIC - commented out, see commit message
# # If not, check if the library exists, and atomics work with it.
# if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
# check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
# if(HAVE_CXX_LIBATOMICS64)
# list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
# check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
# if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
# message(FATAL_ERROR "Host compiler must support std::atomic!")
# endif()
# else()
# message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
# endif()
# endif()

## TODO: This define is only used for the legacy atomic operations in
## llvm's Atomic.h, which should be replaced. Other code simply
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
/// long double __powl_finite(long double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
TLI_DEFINE_STRING_INTERNAL("__powl_finite")

TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")

TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")

TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")

/// double __sincospi_stret(double x);
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")
Expand Down
8 changes: 8 additions & 0 deletions llvm/include/llvm/MC/MCSubtargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class MCSubtargetInfo {
auto Found = std::lower_bound(ProcDesc.begin(), ProcDesc.end(), CPU);
return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
}

ArrayRef<SubtargetSubTypeKV> getCPUTable() const {
return ProcDesc;
}

ArrayRef<SubtargetFeatureKV> getFeatureTable() const {
return ProcFeatures;
}
};

} // end namespace llvm
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/Analysis/MemoryBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
{LibFunc_realloc, {ReallocLike, 2, 1, -1}},
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
{LibFunc_strndup, {StrDupLike, 2, 1, -1}}
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},

{LibFunc_rust_alloc, {MallocLike, 2, 0, -1}},
{LibFunc_rust_realloc, {ReallocLike, 4, 3, -1}},
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
};

Expand Down Expand Up @@ -398,7 +401,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
ExpectedNumParams = 2;
else if (TLIFn == LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t || // delete(void*, align_val_t, nothrow)
TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t) // delete[](void*, align_val_t, nothrow)
TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t || // delete[](void*, align_val_t, nothrow)
TLIFn == LibFunc_rust_dealloc)
ExpectedNumParams = 3;
else
return nullptr;
Expand Down
22 changes: 22 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
else
return false;
}

case LibFunc_rust_alloc:
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
FTy.getParamType(0)->isIntegerTy() &&
FTy.getParamType(1)->isIntegerTy() &&
FTy.getParamType(2)->isPointerTy());

case LibFunc_rust_dealloc:
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
FTy.getParamType(0)->isPointerTy() &&
FTy.getParamType(1)->isIntegerTy() &&
FTy.getParamType(2)->isIntegerTy());

case LibFunc_rust_realloc:
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
FTy.getParamType(0)->isPointerTy() &&
FTy.getParamType(1)->isIntegerTy() &&
FTy.getParamType(2)->isIntegerTy() &&
FTy.getParamType(3)->isIntegerTy() &&
FTy.getParamType(4)->isIntegerTy() &&
FTy.getParamType(5)->isPointerTy());

case LibFunc::NumLibFuncs:
break;
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ RTDyldMemoryManager::getSymbolAddressInProcess(const std::string &Name) {
if (Name == "stat") return (uint64_t)&stat;
if (Name == "fstat") return (uint64_t)&fstat;
if (Name == "lstat") return (uint64_t)&lstat;
if (Name == "stat64") return (uint64_t)&stat64;
if (Name == "fstat64") return (uint64_t)&fstat64;
if (Name == "lstat64") return (uint64_t)&lstat64;
// if (Name == "stat64") return (uint64_t)&stat64;
// if (Name == "fstat64") return (uint64_t)&fstat64;
// if (Name == "lstat64") return (uint64_t)&lstat64;
if (Name == "atexit") return (uint64_t)&atexit;
if (Name == "mknod") return (uint64_t)&mknod;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/Unix/Program.inc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
static long ArgMax = sysconf(_SC_ARG_MAX);
// POSIX requires that _POSIX_ARG_MAX is 4096, which is the lowest possible
// value for ARG_MAX on a POSIX compliant system.
static long ArgMin = _POSIX_ARG_MAX;
static long ArgMin = 4096;

// This the same baseline used by xargs.
long EffectiveArgMax = 128 * 1024;
Expand Down
9 changes: 8 additions & 1 deletion llvm/lib/Target/X86/X86MCInstLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,14 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,

const MCSymbolRefExpr *Sym = MCSymbolRefExpr::create(
MCInstLowering.GetSymbolFromOperand(MI.getOperand(3)), SRVK, Ctx);
bool UseGot = MMI->getModule()->getRtLibUseGOT();

// As of binutils 2.32, ld has a bogus TLS relaxation error when the GD/LD
// code sequence using R_X86_64_GOTPCREL (instead of R_X86_64_GOTPCRELX) is
// attempted to be relaxed to IE/LE (binutils PR24784). Work around the bug by
// only using GOT when GOTPCRELX is enabled.
// TODO Delete the workaround when GOTPCRELX becomes commonplace.
bool UseGot = MMI->getModule()->getRtLibUseGOT() &&
Ctx.getAsmInfo()->canRelaxRelocations();

if (Is64Bits) {
bool NeedsPadding = SRVK == MCSymbolRefExpr::VK_TLSGD;
Expand Down
16 changes: 10 additions & 6 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3355,6 +3355,7 @@ int BoUpSLP::getSpillCost() const {
});

// Now find the sequence of instructions between PrevInst and Inst.
unsigned NumCalls = 0;
BasicBlock::reverse_iterator InstIt = ++Inst->getIterator().getReverse(),
PrevInstIt =
PrevInst->getIterator().getReverse();
Expand All @@ -3367,16 +3368,19 @@ int BoUpSLP::getSpillCost() const {
// Debug informations don't impact spill cost.
if ((isa<CallInst>(&*PrevInstIt) &&
!isa<DbgInfoIntrinsic>(&*PrevInstIt)) &&
&*PrevInstIt != PrevInst) {
SmallVector<Type*, 4> V;
for (auto *II : LiveValues)
V.push_back(VectorType::get(II->getType(), BundleWidth));
Cost += TTI->getCostOfKeepingLiveOverCall(V);
}
&*PrevInstIt != PrevInst)
NumCalls++;

++PrevInstIt;
}

if (NumCalls) {
SmallVector<Type*, 4> V;
for (auto *II : LiveValues)
V.push_back(VectorType::get(II->getType(), BundleWidth));
Cost += NumCalls * TTI->getCostOfKeepingLiveOverCall(V);
}

PrevInst = Inst;
}

Expand Down
13 changes: 11 additions & 2 deletions llvm/test/CodeGen/X86/tls-no-plt.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
; RUN: llc < %s -mtriple=i386-linux-musl -relocation-model=pic | FileCheck --check-prefixes=CHECK,X86 %s
; RUN: llc < %s -mtriple=x86_64-linux-musl -relocation-model=pic | FileCheck --check-prefixes=CHECK,X64 %s
; RUN: llc < %s -mtriple=i386-linux-musl -relocation-model=pic -relax-elf-relocations=true | FileCheck --check-prefixes=CHECK,X86 %s
; RUN: llc < %s -mtriple=x86_64-linux-musl -relocation-model=pic -relax-elf-relocations=true | FileCheck --check-prefixes=CHECK,X64 %s

;; If GOTPCRELX is disabled, don't use GOT for __tls_get_addr to work around
;; a ld.bfd bug (binutils PR24784).
; RUN: llc < %s -mtriple=i386-linux-musl -relocation-model=pic | FileCheck --check-prefixes=CHECK,X86-PLT %s
; RUN: llc < %s -mtriple=x86_64-linux-musl -relocation-model=pic | FileCheck --check-prefixes=CHECK,X64-PLT %s

@gd = thread_local global i32 0
@ld = internal thread_local global i32 0
Expand All @@ -9,9 +14,11 @@ entry:
; CHECK-LABEL: get_gd:
; X86: leal gd@TLSGD(%ebx), %eax
; X86: calll *___tls_get_addr@GOT(%ebx)
; X86-PLT: calll ___tls_get_addr@PLT

; X64: leaq gd@TLSGD(%rip), %rdi
; X64: callq *__tls_get_addr@GOTPCREL(%rip)
; X64-PLT: callq __tls_get_addr@PLT
ret i32* @gd
}

Expand All @@ -20,9 +27,11 @@ define i32* @get_ld() {
; CHECK-LABEL: get_ld:
; X86: leal ld@TLSLDM(%ebx), %eax
; X86: calll *___tls_get_addr@GOT(%ebx)
; X86-PLT: calll ___tls_get_addr@PLT

; X64: leaq ld@TLSLD(%rip), %rdi
; X64: callq *__tls_get_addr@GOTPCREL(%rip)
; X64-PLT: callq __tls_get_addr@PLT
ret i32* @ld
}

Expand Down