Skip to content

Fix build on Clear Linux and Android device #34211

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

Merged
merged 2 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,30 @@ else()
endif()

if(NOT CLR_CMAKE_HOST_ARCH_WASM)
if(NOT CLR_CMAKE_TARGET_ANDROID) # Android requires PIC and CMake handles this so we don't need the check
# All code we build should be compiled as position independent
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if("CXX" IN_LIST languages)
set(CLR_PIE_LANGUAGE CXX)
else()
set(CLR_PIE_LANGUAGE C)
endif()
check_pie_supported(OUTPUT_VARIABLE PIE_SUPPORT_OUTPUT LANGUAGES ${CLR_PIE_LANGUAGE})
if(NOT MSVC AND NOT CMAKE_${CLR_PIE_LANGUAGE}_LINK_PIE_SUPPORTED)
message(WARNING "PIE is not supported at link time: ${PIE_SUPPORT_OUTPUT}.\n"
"PIE link options will not be passed to linker.")
endif()
# Skip check_pie_supported call on Android as ld from llvm toolchain with NDK API level 21
# complains about missing linker flag `-no-pie` (while level 28's ld does support this flag,
# but since we know that PIE is supported, we can safely skip this redundant check).
if(NOT CLR_CMAKE_TARGET_ANDROID)
# All code we build should be compiled as position independent
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if("CXX" IN_LIST languages)
set(CLR_PIE_LANGUAGE CXX)
else()
set(CLR_PIE_LANGUAGE C)
endif()
check_pie_supported(OUTPUT_VARIABLE PIE_SUPPORT_OUTPUT LANGUAGES ${CLR_PIE_LANGUAGE})
if(NOT MSVC AND NOT CMAKE_${CLR_PIE_LANGUAGE}_LINK_PIE_SUPPORTED)
message(WARNING "PIE is not supported at link time: ${PIE_SUPPORT_OUTPUT}.\n"
"PIE link options will not be passed to linker.")
endif()
endif(NOT CLR_CMAKE_TARGET_ANDROID)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif(NOT CLR_CMAKE_TARGET_ANDROID)
endif(NOT CLR_CMAKE_HOST_ARCH_WASM)

string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWERCASE_CMAKE_BUILD_TYPE)
if(LOWERCASE_CMAKE_BUILD_TYPE STREQUAL debug)
# Clear _FORTIFY_SOURCE=2, if set
string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endif()
1 change: 0 additions & 1 deletion src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export PYTHON
usage_list+=("-nopgooptimize: do not use profile guided optimizations.")
usage_list+=("-pgoinstrument: generate instrumented code for profile guided optimization enabled binaries.")
usage_list+=("-skipcrossarchnative: Skip building cross-architecture native binaries.")
usage_list+=("-skiprestoreoptdata: skip restoring optimization data.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@am11 this seems like an unintentional change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akoeplinger, I called it out here #34211 (comment). This option in help menu was removed from code, the case-esac block which handles options, and superseded by -nopgooptimize. For example, to quickly build coreclr native components with PAL tests on an unsupported Unix (e.g. SunOS, QNX), where dontet(1)/msbuild is currently unavailable, we can use:

./src/coreclr/build-runtime.sh -skipgenerateversion -nopgooptimize \
    -cmakeargs -DCLR_CMAKE_BUILD_TESTS=1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. It's still in src/coreclr/build-runtime.cmd that's why I was confused :)

usage_list+=("-staticanalyzer: skip native image generation.")

setup_dirs_local()
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/binder/fusionassemblyname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ HRESULT CPropertyArray::Get(DWORD PropertyId,

if (pItem->cb > *pcbProperty)
hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
else if (pItem->cb)
else if (pItem->cb && pvProperty)
memcpy(pvProperty, (pItem->cb > sizeof(DWORD) ?
pItem->pv : (LPBYTE) &(pItem->pv)), pItem->cb);

Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/src/inc/ceefilegenwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,21 @@ inline LPWSTR CeeFileGenWriter::getResourceFileName() {
}

inline HRESULT CeeFileGenWriter::setDllSwitch(bool dllSwitch) {
if((m_dllSwitch = dllSwitch)) m_objSwitch = FALSE; return S_OK;
if((m_dllSwitch = dllSwitch))
m_objSwitch = FALSE;

return S_OK;
}

inline bool CeeFileGenWriter::getDllSwitch() {
return m_dllSwitch;
}

inline HRESULT CeeFileGenWriter::setObjSwitch(bool objSwitch) {
if((m_objSwitch = objSwitch)) m_dllSwitch = FALSE; return S_OK;
if((m_objSwitch = objSwitch))
m_dllSwitch = FALSE;

return S_OK;
}

inline bool CeeFileGenWriter::getObjSwitch() {
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/pal/src/libunwind/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_definitions(-D_GNU_SOURCE)
add_definitions("-Ddwarf_search_unwind_table_int=UNW_OBJ(dwarf_search_unwind_table_int)")

# Disable warning due to incorrect format specifier in debugging printf via the Debug macro
add_compile_options(-Wno-format)
add_compile_options(-Wno-format -Wno-format-security)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-header-guard)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/vm/object.inl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ __forceinline BOOL Nullable::IsNullableForType(TypeHandle type, MethodTable* par
return FALSE;
if (!type.AsMethodTable()->HasInstantiation()) // shortcut, if it is not generic it can't be Nullable<T>
return FALSE;
return Nullable::IsNullableForTypeHelper(type.AsMethodTable(), paramMT);
return Nullable::IsNullableForTypeHelper(type.AsMethodTable(), paramMT);
}

//===============================================================================
Expand All @@ -241,7 +241,7 @@ __forceinline BOOL Nullable::IsNullableForTypeNoGC(TypeHandle type, MethodTable*
return FALSE;
if (!type.AsMethodTable()->HasInstantiation()) // shortcut, if it is not generic it can't be Nullable<T>
return FALSE;
return Nullable::IsNullableForTypeHelperNoGC(type.AsMethodTable(), paramMT);
return Nullable::IsNullableForTypeHelperNoGC(type.AsMethodTable(), paramMT);
}

//===============================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ add_compile_options(-Wno-empty-translation-unit)
add_compile_options(-Wno-cast-align)
add_compile_options(-Wno-typedef-redefinition)
add_compile_options(-Wno-c11-extensions)
add_compile_options(-Wno-unknown-pragmas)
add_compile_options(-I${CMAKE_CURRENT_SOURCE_DIR}/Common)
add_compile_options(-I${CMAKE_CURRENT_BINARY_DIR}/Common)
add_compile_options(-g)
if(CMAKE_C_COMPILER_ID STREQUAL Clang)
add_compile_options(-Wthread-safety)
add_compile_options(-Wno-thread-safety-analysis)
elseif(CMAKE_C_COMPILER_ID STREQUAL GNU)
add_compile_options(-Wno-stringop-truncation)
endif()

# Suppress warnings-as-errors in release branches to reduce servicing churn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void GlobalizationNative_ChangeCase(
// improvement on longer strings.)

UBool isError = FALSE;
(void)isError; // only used for assert
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;

Expand Down Expand Up @@ -75,6 +76,7 @@ void GlobalizationNative_ChangeCaseInvariant(
// See algorithmic comment in ChangeCase.

UBool isError = FALSE;
(void)isError; // only used for assert
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;

Expand Down Expand Up @@ -119,6 +121,7 @@ void GlobalizationNative_ChangeCaseTurkish(
// See algorithmic comment in ChangeCase.

UBool isError = FALSE;
(void)isError; // only used for assert
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;

Expand Down
24 changes: 12 additions & 12 deletions src/libraries/Native/Unix/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ c_static_assert(PAL_S_IFSOCK == S_IFSOCK);
// declared by the dirent.h header on the local system.
// (AIX doesn't have dirent d_type, so none of this there)
#if defined(DT_UNKNOWN)
c_static_assert(PAL_DT_UNKNOWN == DT_UNKNOWN);
c_static_assert(PAL_DT_FIFO == DT_FIFO);
c_static_assert(PAL_DT_CHR == DT_CHR);
c_static_assert(PAL_DT_DIR == DT_DIR);
c_static_assert(PAL_DT_BLK == DT_BLK);
c_static_assert(PAL_DT_REG == DT_REG);
c_static_assert(PAL_DT_LNK == DT_LNK);
c_static_assert(PAL_DT_SOCK == DT_SOCK);
c_static_assert(PAL_DT_WHT == DT_WHT);
c_static_assert((int)PAL_DT_UNKNOWN == (int)DT_UNKNOWN);
c_static_assert((int)PAL_DT_FIFO == (int)DT_FIFO);
c_static_assert((int)PAL_DT_CHR == (int)DT_CHR);
c_static_assert((int)PAL_DT_DIR == (int)DT_DIR);
c_static_assert((int)PAL_DT_BLK == (int)DT_BLK);
c_static_assert((int)PAL_DT_REG == (int)DT_REG);
c_static_assert((int)PAL_DT_LNK == (int)DT_LNK);
c_static_assert((int)PAL_DT_SOCK == (int)DT_SOCK);
c_static_assert((int)PAL_DT_WHT == (int)DT_WHT);
#endif

// Validate that our Lock enum value are correct for the platform
Expand Down Expand Up @@ -1061,7 +1061,7 @@ char* SystemNative_GetLine(FILE* stream)
char* lineptr = NULL;
size_t n = 0;
ssize_t length = getline(&lineptr, &n, stream);

return length >= 0 ? lineptr : NULL;
}

Expand Down Expand Up @@ -1230,7 +1230,7 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, const char* srcPath, const char
{
return -1;
}

ret = unlink(destPath);
if (ret != 0)
{
Expand Down Expand Up @@ -1430,7 +1430,7 @@ char* SystemNative_RealPath(const char* path)

int32_t SystemNative_LockFileRegion(intptr_t fd, int64_t offset, int64_t length, int16_t lockType)
{
if (offset < 0 || length < 0)
if (offset < 0 || length < 0)
{
errno = EINVAL;
return -1;
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Native/Unix/System.Native/pal_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void SystemNative_RegisterForSigChld(SigChldCallback callback)
static void InstallSignalHandler(int sig, bool skipWhenSigIgn)
{
int rv;
(void)rv; // only used for assert
struct sigaction* orig = OrigActionFor(sig);

if (skipWhenSigIgn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,16 @@ int32_t CryptoNative_GetDsaParameters(
const BIGNUM** y, int32_t* yLength,
const BIGNUM** x, int32_t* xLength)
{
if (!dsa || !p || !q || !g || !y || !x)
{
assert(false);

// since these parameters are 'out' parameters in managed code, ensure they are initialized
if (p) *p = NULL; if (pLength) *pLength = 0;
if (q) *q = NULL; if (qLength) *qLength = 0;
if (g) *g = NULL; if (gLength) *gLength = 0;
if (y) *y = NULL; if (yLength) *yLength = 0;
if (x) *x = NULL; if (xLength) *xLength = 0;
return 0;
}
assert(p != NULL);
assert(q != NULL);
assert(g != NULL);
assert(y != NULL);
assert(x != NULL);
assert(pLength != NULL);
assert(qLength != NULL);
assert(gLength != NULL);
assert(yLength != NULL);
assert(xLength != NULL);

DSA_get0_pqg(dsa, p, q, g);
*pLength = BN_num_bytes(*p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,12 @@ int32_t CryptoNative_GetECKeyParameters(
const BIGNUM** qy, int32_t* cbQy,
const BIGNUM** d, int32_t* cbD)
{
// Verify the out parameters. Note out parameters used to minimize pinvoke calls.
if (!key ||
!qx || !cbQx ||
!qy || !cbQy ||
(includePrivate && (!d || !cbD)))
{
assert(false);

// Since these parameters are 'out' parameters in managed code, ensure they are initialized
if (qx) *qx = NULL; if (cbQx) *cbQx = 0;
if (qy) *qy = NULL; if (cbQy) *cbQy = 0;
if (d) *d = NULL; if (cbD) *cbD = 0;

return 0;
}
assert(qx != NULL);
assert(cbQx != NULL);
assert(qy != NULL);
assert(cbQy != NULL);
assert(d != NULL);
assert(cbD != NULL);

// Get the public key and curve
int rc = 0;
Expand Down Expand Up @@ -158,34 +149,26 @@ int32_t CryptoNative_GetECCurveParameters(
const BIGNUM** cofactor, int32_t* cbCofactor,
const BIGNUM** seed, int32_t* cbSeed)
{
assert(p != NULL);
assert(cbP != NULL);
assert(a != NULL);
assert(cbA != NULL);
assert(b != NULL);
assert(cbB != NULL);
assert(gx != NULL);
assert(cbGx != NULL);
assert(gy != NULL);
assert(cbGy != NULL);
assert(order != NULL);
assert(cbOrder != NULL);
assert(cofactor != NULL);
assert(cbCofactor != NULL);
assert(seed != NULL);
assert(cbSeed != NULL);

// Get the public key parameters first in case any of its 'out' parameters are not initialized
int32_t rc = CryptoNative_GetECKeyParameters(key, includePrivate, qx, cbQx, qy, cbQy, d, cbD);

// Verify the out parameters. Note out parameters used to minimize pinvoke calls.
if (!p || !cbP ||
!a || !cbA ||
!b || !cbB ||
!gx || !cbGx ||
!gy || !cbGy ||
!order || !cbOrder ||
!cofactor || !cbCofactor ||
!seed || !cbSeed)
{
assert(false);

// Since these parameters are 'out' parameters in managed code, ensure they are initialized
if (p) *p = NULL; if (cbP) *cbP = 0;
if (a) *a = NULL; if (cbA) *cbA = 0;
if (b) *b = NULL; if (cbB) *cbB = 0;
if (gx) *gx = NULL; if (cbGx) *cbGx = 0;
if (gy) *gy = NULL; if (cbGy) *cbGy = 0;
if (order) *order = NULL; if (cbOrder) *cbOrder = 0;
if (cofactor) *cofactor = NULL; if (cbCofactor) *cbCofactor = 0;
if (seed) *seed = NULL; if (cbSeed) *cbSeed = 0;

return 0;
}

const EC_GROUP* group = NULL;
const EC_POINT* G = NULL;
const EC_METHOD* curveMethod = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static int GetOpenSslPadding(RsaPadding padding)
case NoPadding:
return RSA_NO_PADDING;
}

return RSA_NO_PADDING;
}

static int HasNoPrivateKey(RSA* rsa)
Expand Down