Skip to content

Commit

Permalink
Assortment of Rust-related build fixes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexcrichton committed Jul 2, 2019
1 parent b11adab commit 1b534e9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
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
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
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

0 comments on commit 1b534e9

Please sign in to comment.