Skip to content

Commit 1b534e9

Browse files
committed
Assortment of Rust-related build fixes
This commit is an assortment of build fixes for LLVM that we've applied for rust-lang/rust. These are unlikely to ever go upstream, but if we could upstream them somehow that'd definitely be great! In any case for now some rationale for these patches are: * We build on ancient CentOS containers for i686/x86_64 Linux releases. The libc header files there are insanely old and despite using a recent gcc/clang release the libc headers cause issues. Some various pieces are commented out or altered to pieces of LLVM that aren't exercised or used much by LLVM. * Sometimes there's some miscellaneous MSVC things here and there, but nothing crticial. For details of changes to specific files: ----------------------------------------------------------------------- * llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp Fix compile on dist-i686-linux builder If this lines are present then we apparently get errors [1] when compiling in the current [2] dist-i686-linux container. Attempts to upgrade both gcc and binutils did not fix the error, so it appears that this may just be a bug in the super old glibc we're using on the dist-i686-linux container. We don't actually need this code anyway, so just work around these issues by removing references to the `*64` functions. This'll get things compiling locally and shouldn't be a regression in functionality. [1]: https://travis-ci.org/rust-lang/rust/jobs/257578199 [2]: https://github.com/rust-lang/rust/tree/eba9d7f08ce5c90549ee52337aca0010ad566f0d/src/ci/docker/dist-i686-linux ----------------------------------------------------------------------- * llvm/cmake/modules/CheckAtomic.cmake Disable checks for libatomic for now For whatever reason this is failing the i686-freebsd builder in the Rust repo as-of this red-hot moment. The build seems to work fine without it so let's just remove it for now and pray there's a better fix later. Although if you're reading this and know of a better fix, we'd love to remove this! ----------------------------------------------------------------------- * lld/CMakeLists.txt Compile with /MT on MSVC Can't seem to figure out how to do this without this patch... ----------------------------------------------------------------------- * compiler-rt/lib/asan/asan_linux.c * compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc * llvm/lib/Support/Unix/Program.inc Fix compile on dist-x86_64-linux builder for LLVM/sanitizers Apparently glibc is so old it doesn't have the _POSIX_ARG_MAX constant. This shouldn't affect anything we use anyway though. Apply similar treatment to various definitions of things compiler-rt. https://travis-ci.org/rust-lang/rust/jobs/399333071
1 parent b11adab commit 1b534e9

File tree

7 files changed

+37
-26
lines changed

7 files changed

+37
-26
lines changed

compiler-rt/lib/asan/asan_linux.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void AsanCheckIncompatibleRT() {
214214
// the functions in dynamic ASan runtime instead of the functions in
215215
// system libraries, causing crashes later in ASan initialization.
216216
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
217-
char filename[PATH_MAX];
217+
char filename[4096];
218218
MemoryMappedSegment segment(filename, sizeof(filename));
219219
while (proc_maps.Next(&segment)) {
220220
if (IsDynamicRTName(segment.filename)) {

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,12 +698,8 @@ u32 GetNumberOfCPUs() {
698698
}
699699
internal_close(fd);
700700
return n_cpus;
701-
#elif SANITIZER_SOLARIS
702-
return sysconf(_SC_NPROCESSORS_ONLN);
703701
#else
704-
cpu_set_t CPUs;
705-
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
706-
return CPU_COUNT(&CPUs);
702+
return sysconf(_SC_NPROCESSORS_ONLN);
707703
#endif
708704
}
709705

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ typedef struct user_fpregs elf_fpregset_t;
106106
#endif
107107

108108
#if SANITIZER_LINUX && !SANITIZER_ANDROID
109+
#include <stdio.h>
109110
#include <glob.h>
110111
#include <obstack.h>
111112
#include <mqueue.h>
@@ -1010,9 +1011,9 @@ CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
10101011
#endif
10111012

10121013
#if SANITIZER_LINUX && (__ANDROID_API__ >= 21 || __GLIBC_PREREQ (2, 14))
1013-
CHECK_TYPE_SIZE(mmsghdr);
1014-
CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr);
1015-
CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);
1014+
// CHECK_TYPE_SIZE(mmsghdr);
1015+
// CHECK_SIZE_AND_OFFSET(mmsghdr, msg_hdr);
1016+
// CHECK_SIZE_AND_OFFSET(mmsghdr, msg_len);
10161017
#endif
10171018

10181019
COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));

lld/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
210210
)
211211
endif()
212212

213+
if (MSVC)
214+
FOREACH(flag
215+
CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
216+
CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
217+
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
218+
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT)
219+
if (MSVC)
220+
STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}")
221+
SET("${flag}" "${${flag}}")
222+
endif (MSVC)
223+
ENDFOREACH()
224+
endif()
225+
213226
add_subdirectory(Common)
214227
add_subdirectory(lib)
215228
add_subdirectory(tools/lld)

llvm/cmake/modules/CheckAtomic.cmake

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,20 @@ else()
6262
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
6363
endif()
6464

65-
# If not, check if the library exists, and atomics work with it.
66-
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
67-
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
68-
if(HAVE_CXX_LIBATOMICS64)
69-
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
70-
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
71-
if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
72-
message(FATAL_ERROR "Host compiler must support std::atomic!")
73-
endif()
74-
else()
75-
message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
76-
endif()
77-
endif()
65+
# RUST-SPECIFIC - commented out, see commit message
66+
# # If not, check if the library exists, and atomics work with it.
67+
# if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
68+
# check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
69+
# if(HAVE_CXX_LIBATOMICS64)
70+
# list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
71+
# check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
72+
# if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
73+
# message(FATAL_ERROR "Host compiler must support std::atomic!")
74+
# endif()
75+
# else()
76+
# message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
77+
# endif()
78+
# endif()
7879

7980
## TODO: This define is only used for the legacy atomic operations in
8081
## llvm's Atomic.h, which should be replaced. Other code simply

llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ RTDyldMemoryManager::getSymbolAddressInProcess(const std::string &Name) {
243243
if (Name == "stat") return (uint64_t)&stat;
244244
if (Name == "fstat") return (uint64_t)&fstat;
245245
if (Name == "lstat") return (uint64_t)&lstat;
246-
if (Name == "stat64") return (uint64_t)&stat64;
247-
if (Name == "fstat64") return (uint64_t)&fstat64;
248-
if (Name == "lstat64") return (uint64_t)&lstat64;
246+
// if (Name == "stat64") return (uint64_t)&stat64;
247+
// if (Name == "fstat64") return (uint64_t)&fstat64;
248+
// if (Name == "lstat64") return (uint64_t)&lstat64;
249249
if (Name == "atexit") return (uint64_t)&atexit;
250250
if (Name == "mknod") return (uint64_t)&mknod;
251251

llvm/lib/Support/Unix/Program.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
462462
static long ArgMax = sysconf(_SC_ARG_MAX);
463463
// POSIX requires that _POSIX_ARG_MAX is 4096, which is the lowest possible
464464
// value for ARG_MAX on a POSIX compliant system.
465-
static long ArgMin = _POSIX_ARG_MAX;
465+
static long ArgMin = 4096;
466466

467467
// This the same baseline used by xargs.
468468
long EffectiveArgMax = 128 * 1024;

0 commit comments

Comments
 (0)