macOS: Link with no-weak-imports (#4056)

This commit is contained in:
Teddy Reed 2018-01-12 20:34:45 -05:00 committed by GitHub
parent bf0eb6f36f
commit 8272c028dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 15 deletions

View File

@ -185,6 +185,7 @@ if(APPLE)
ADD_OSQUERY_LINK_CORE("-Wl,-dead_strip")
ADD_OSQUERY_LINK_CORE("-mmacosx-version-min=${OSX_VERSION_MIN}")
ADD_OSQUERY_LINK_CORE("-Wl,-cache_path_lto,${CMAKE_BINARY_DIR}/ltocache")
ADD_OSQUERY_LINK_CORE("-Wl,-no_weak_imports")
elseif(LINUX OR FREEBSD)
ADD_OSQUERY_LINK_CORE("-Wl,-zrelro -Wl,-znow")
if(NOT DEFINED ENV{SANITIZE} AND NOT DEFINED ENV{DEBUG})

View File

@ -42,15 +42,10 @@ const std::map<std::string, uint32_t> kRootlessConfigFlags = {
#define kIODeviceTreeChosenPath_ "IODeviceTree:/options"
typedef uint32_t csr_config_t;
#if !defined(DARWIN_10_9)
// mark these symbols as weakly linked, as they may not be available
// at runtime on older OS X versions.
// https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
extern "C" {
int csr_check(csr_config_t mask) __attribute__((weak_import));
int csr_get_active_config(csr_config_t* config) __attribute__((weak_import));
int csr_check(csr_config_t mask);
int csr_get_active_config(csr_config_t* config);
};
#endif
Status genCsrConfigFromNvram(uint32_t& config) {
auto chosen =
@ -107,13 +102,6 @@ QueryData genSIPConfig(QueryContext& context) {
}
QueryData results;
#if !defined(DARWIN_10_9)
// check if weakly linked symbols exist
if (csr_get_active_config == nullptr || csr_check == nullptr) {
return {};
}
csr_config_t config = 0;
csr_get_active_config(&config);
@ -147,7 +135,6 @@ QueryData genSIPConfig(QueryContext& context) {
}
results.push_back(r);
}
#endif
return results;
}