Skip to content

Commit c6b34ad

Browse files
Prepend target prefix to basename
1 parent 0ac2d5f commit c6b34ad

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,10 +1355,21 @@ int __llvm_write_custom_profile(const char *Target,
13551355
TargetFilename =
13561356
(char *)COMPILER_RT_ALLOCA(FilenameLength + TargetLength + 2);
13571357

1358+
/* Find file basename and path sizes */
1359+
int32_t DirEnd = FilenameLength - 1;
1360+
while (DirEnd >= 0 && !IS_DIR_SEPARATOR(Filename[DirEnd])) {
1361+
DirEnd--;
1362+
}
1363+
uint32_t DirSize = DirEnd + 1, BaseSize = FilenameLength - DirSize;
1364+
13581365
/* Prepend "TARGET." to current filename */
1359-
memcpy(TargetFilename, Target, TargetLength);
1360-
TargetFilename[TargetLength] = '.';
1361-
memcpy(TargetFilename + 1 + TargetLength, Filename, FilenameLength);
1366+
if (DirSize > 0) {
1367+
memcpy(TargetFilename, Filename, DirSize);
1368+
}
1369+
memcpy(TargetFilename + DirSize, Target, TargetLength);
1370+
TargetFilename[TargetLength + DirSize] = '.';
1371+
memcpy(TargetFilename + DirSize + 1 + TargetLength, Filename + DirSize,
1372+
BaseSize);
13621373
TargetFilename[FilenameLength + 1 + TargetLength] = 0;
13631374

13641375
/* Check if there is llvm/runtime version mismatch. */

0 commit comments

Comments
 (0)