Skip to content

Commit a6932ad

Browse files
deps: ICU fix that should land upstream
1 parent 9807ede commit a6932ad

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

deps/icu-small/source/tools/genccode/genccode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum {
7070
#ifdef CAN_GENERATE_OBJECTS
7171
kOptObject,
7272
kOptMatchArch,
73+
kOptCpuArch,
7374
kOptSkipDllExport,
7475
#endif
7576
kOptFilename,
@@ -86,6 +87,7 @@ static UOption options[]={
8687
#ifdef CAN_GENERATE_OBJECTS
8788
/*6*/UOPTION_DEF("object", 'o', UOPT_NO_ARG),
8889
UOPTION_DEF("match-arch", 'm', UOPT_REQUIRES_ARG),
90+
UOPTION_DEF("cpu-arch", 'c', UOPT_REQUIRES_ARG),
8991
UOPTION_DEF("skip-dll-export", '\0', UOPT_NO_ARG),
9092
#endif
9193
UOPTION_DEF("filename", 'f', UOPT_REQUIRES_ARG),
@@ -131,6 +133,7 @@ main(int argc, char* argv[]) {
131133
"\t-o or --object write a .obj file instead of .c\n"
132134
"\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n"
133135
"\t ELF format defaults to i386. Windows defaults to the native platform.\n"
136+
"\t-c or --cpu-arch Specify a CPU architecture for which to write a .obj file for ClangCL on Windows\n"
134137
"\t--skip-dll-export Don't export the ICU data entry point symbol (for use when statically linking)\n");
135138
#endif
136139
fprintf(stderr,
@@ -196,6 +199,7 @@ main(int argc, char* argv[]) {
196199
writeObjectCode(filename, options[kOptDestDir].value,
197200
options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL,
198201
options[kOptMatchArch].doesOccur ? options[kOptMatchArch].value : NULL,
202+
options[kOptCpuArch].doesOccur ? options[kOptCpuArch].value : NULL,
199203
options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
200204
NULL,
201205
0,

deps/icu-small/source/tools/pkgdata/pkgdata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ static int32_t pkg_executeOptions(UPKGOptions *o) {
776776
o->entryName,
777777
(optMatchArch[0] == 0 ? nullptr : optMatchArch),
778778
nullptr,
779+
nullptr,
779780
gencFilePath,
780781
sizeof(gencFilePath),
781782
true);

deps/icu-small/source/tools/toolutil/pkg_genc.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,12 @@ getOutFilename(
799799

800800
#ifdef CAN_GENERATE_OBJECTS
801801
static void
802-
getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char *optMatchArch) {
802+
getArchitecture(
803+
uint16_t *pCPU,
804+
uint16_t *pBits,
805+
UBool *pIsBigEndian,
806+
const char *optMatchArch,
807+
const char *optCpuArch) {
803808
union {
804809
char bytes[2048];
805810
#ifdef U_ELF
@@ -847,7 +852,24 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char
847852
# if defined(_M_IX86)
848853
*pCPU = IMAGE_FILE_MACHINE_I386;
849854
# else
850-
*pCPU = IMAGE_FILE_MACHINE_UNKNOWN;
855+
// Linker for ClangCL doesn't handle IMAGE_FILE_MACHINE_UNKNOWN the same as
856+
// linker for MSVC. Because of this optCpuArch is used to define the CPU
857+
// architecture in that case. While _M_AMD64 and _M_ARM64 could be used,
858+
// this would potentially be problematic when cross-compiling as this code
859+
// would most likely be ran on host machine to generate the .obj file for
860+
// the target architecture.
861+
# if defined(__clang__)
862+
if (strcmp(optCpuArch, "x64") == 0) {
863+
*pCPU = IMAGE_FILE_MACHINE_AMD64;
864+
} else if (strcmp(optCpuArch, "arm64") == 0) {
865+
*pCPU = IMAGE_FILE_MACHINE_ARM64;
866+
} else {
867+
// This should never happen.
868+
*pCPU = IMAGE_FILE_MACHINE_UNKNOWN;
869+
}
870+
# else
871+
*pCPU = IMAGE_FILE_MACHINE_UNKNOWN;
872+
# endif
851873
# endif
852874
# if defined(_M_IA64) || defined(_M_AMD64) || defined (_M_ARM64)
853875
*pBits = 64; // Doesn't seem to be used for anything interesting though?
@@ -934,6 +956,7 @@ writeObjectCode(
934956
const char *destdir,
935957
const char *optEntryPoint,
936958
const char *optMatchArch,
959+
const char *optCpuArch,
937960
const char *optFilename,
938961
char *outFilePath,
939962
size_t outFilePathCapacity,
@@ -1201,7 +1224,7 @@ writeObjectCode(
12011224
#endif
12021225

12031226
/* deal with options, files and the entry point name */
1204-
getArchitecture(&cpu, &bits, &makeBigEndian, optMatchArch);
1227+
getArchitecture(&cpu, &bits, &makeBigEndian, optMatchArch, optCpuArch);
12051228
if (optMatchArch)
12061229
{
12071230
printf("genccode: --match-arch cpu=%hu bits=%hu big-endian=%d\n", cpu, bits, makeBigEndian);

deps/icu-small/source/tools/toolutil/pkg_genc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ writeObjectCode(
9999
const char *destdir,
100100
const char *optEntryPoint,
101101
const char *optMatchArch,
102+
const char *optCpuArch,
102103
const char *optFilename,
103104
char *outFilePath,
104105
size_t outFilePathCapacity,

0 commit comments

Comments
 (0)