Skip to content

Commit 4f41e87

Browse files
committed
Strip out C/C++ library/include directory overrides on older NDK releases
In older versions of the NDK, the CMake/ndk-build scripts manually passed the library/include directories of the C/C++ standard libraries to the compiler command. Pino does not use this approach, and instead relies on its own logic for locating the C/C++ standard library directories. Since this behavior is irrelevant to us — and may even conflict with our own implementation — these arguments are now stripped out to avoid passing them to the compiler.
1 parent 18a89de commit 4f41e87

1 file changed

Lines changed: 49 additions & 8 deletions

File tree

tools/gcc-wrapper/main.c

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ static char* SYSTEM_LIBRARY_PATH[] = {
199199
NULL
200200
};
201201

202+
static const char NDK_CXX_STL_DIRECTORY[] = PATHSEP_M "sources" PATHSEP_M "cxx-stl";
203+
static const char NDK_SYSROOT_INCLUDE_DIRECTORY[] = PATHSEP_M "sysroot" PATHSEP_M "usr" PATHSEP_M "include";
204+
static const char NDK_SYSROOT_LIBRARY_DIRECTORY[] = PATHSEP_M "prebuilt" PATHSEP_M "linux-x86_64" PATHSEP_M "lib" PATHSEP_M "gcc";
205+
202206
static const char USR_DIRECTORY[] = PATHSEP_M "usr";
203207
static const char LIB_DIRECTORY[] = PATHSEP_M "lib";
204208

@@ -1002,21 +1006,55 @@ int main(int argc, char* argv[], char* envp[]) {
10021006
for (index = 0; index < (size_t) argc; index++) {
10031007
cur = argv[index];
10041008

1005-
if (strncmp(cur, GCC_OPT_D, strlen(GCC_OPT_D)) == 0) {
1006-
size = strlen(GCC_OPT_D);
1009+
if (strncmp(cur, GCC_OPT_ISYSTEM, strlen(GCC_OPT_ISYSTEM)) == 0 || strncmp(cur, GCC_OPT_LIBDIR, strlen(GCC_OPT_LIBDIR)) == 0) {
1010+
pattern = GCC_OPT_ISYSTEM;
1011+
1012+
if (strncmp(cur, GCC_OPT_LIBDIR, strlen(GCC_OPT_LIBDIR)) == 0) {
1013+
pattern = GCC_OPT_LIBDIR;
1014+
}
1015+
1016+
size = strlen(pattern);
10071017
offset = 0;
10081018

10091019
cur += size;
1010-
10111020
ch = *cur;
10121021

10131022
if (ch == ZERO) {
1014-
offset++;
1015-
1016-
if ((index + offset) > (size_t) argc) {
1023+
if ((index + ++offset) > (size_t) argc) {
10171024
goto next;
10181025
}
10191026

1027+
cur = argv[index + offset];
1028+
}
1029+
1030+
/*
1031+
In older versions of the NDK, the CMake/ndk-build scripts used to manually pass
1032+
the library/include directories of the C/C++ standard libraries to the compiler command.
1033+
1034+
Pino does not use this approach, and instead relies on its own logic for locating
1035+
the C/C++ standard library directories.
1036+
1037+
Since this is irrelevant to us—and may even cause conflicts with our own implementation—
1038+
strip these arguments out and avoid passing them down to the compiler.
1039+
*/
1040+
if (strstr(cur, NDK_CXX_STL_DIRECTORY) == NULL && strstr(cur, NDK_SYSROOT_INCLUDE_DIRECTORY) == NULL && strstr(cur, NDK_SYSROOT_LIBRARY_DIRECTORY) == NULL) {
1041+
goto next;
1042+
}
1043+
1044+
index += offset;
1045+
1046+
continue;
1047+
} else if (strncmp(cur, GCC_OPT_D, strlen(GCC_OPT_D)) == 0) {
1048+
size = strlen(GCC_OPT_D);
1049+
offset = 0;
1050+
1051+
cur += size;
1052+
ch = *cur;
1053+
1054+
if (ch == ZERO) {
1055+
if ((index + ++offset) > (size_t) argc) {
1056+
goto next;
1057+
}
10201058

10211059
cur = argv[index + offset];
10221060
}
@@ -1044,8 +1082,6 @@ int main(int argc, char* argv[], char* envp[]) {
10441082

10451083
override_libcv = cur;
10461084

1047-
offset++;
1048-
10491085
index += offset;
10501086

10511087
continue;
@@ -1168,6 +1204,10 @@ int main(int argc, char* argv[], char* envp[]) {
11681204
strncpy(override_triplet, cur, size);
11691205
override_triplet[size] = '\0';
11701206

1207+
if (strcmp(override_triplet, "armv5te") == 0) {
1208+
strcpy(override_triplet, "armv5");
1209+
}
1210+
11711211
/* Vendor */
11721212
strcat(override_triplet, VENDOR_UNKNOWN);
11731213

@@ -2269,6 +2309,7 @@ int main(int argc, char* argv[], char* envp[]) {
22692309
free(nz_sysroot_directory);
22702310
free(parent_directory);
22712311
free(non_prefixed_triplet);
2312+
free(override_triplet);
22722313

22732314
#if defined(PINO)
22742315
free(android_api);

0 commit comments

Comments
 (0)