Skip to content

Commit b04b373

Browse files
authored
[LIBCLC] Drop AMD code object version from libclc (#18294)
Upstream recently bumped the default AMD code object version to 6, which is only supported by ROCm 6.3 and above. There is a flag `-mcode-object-version=` to make the compiler use an older version. But before this patch it broke at the libclc linking stage since libclc had the default value in a module flag. So this patch makes the prepare builtin tool remove this module flag from the libclc bitcode libraries.
1 parent 4681161 commit b04b373

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

libclc/utils/prepare-builtins.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,32 @@ int main(int argc, char **argv) {
8989
if (NamedMDNode *OCLVersion = M->getNamedMetadata("opencl.ocl.version"))
9090
M->eraseNamedMetadata(OCLVersion);
9191

92+
SmallVector<Metadata *, 2> BannedFlags;
9293
// wchar_size flag can cause a mismatch between libclc libraries and
9394
// modules using them. Since wchar is not used by libclc we drop the flag
94-
if (M->getModuleFlag("wchar_size")) {
95+
if (Metadata *F = M->getModuleFlag("wchar_size")) {
96+
BannedFlags.push_back(F);
97+
}
98+
99+
// amdhsa_code_object_version will be provided by the kernel module and may
100+
// be changed by a command line flag.
101+
if (Metadata *F = M->getModuleFlag("amdhsa_code_object_version")) {
102+
BannedFlags.push_back(F);
103+
}
104+
105+
// Re-write module flags but skip banned flags
106+
if (!BannedFlags.empty()) {
95107
SmallVector<Module::ModuleFlagEntry, 4> ModuleFlags;
96108
M->getModuleFlagsMetadata(ModuleFlags);
97109
M->getModuleFlagsMetadata()->clearOperands();
98-
for (const Module::ModuleFlagEntry ModuleFlag : ModuleFlags)
99-
if (ModuleFlag.Key->getString() != "wchar_size")
100-
M->addModuleFlag(ModuleFlag.Behavior, ModuleFlag.Key->getString(),
101-
ModuleFlag.Val);
110+
for (const Module::ModuleFlagEntry ModuleFlag : ModuleFlags) {
111+
if (BannedFlags.end() !=
112+
std::find(BannedFlags.begin(), BannedFlags.end(), ModuleFlag.Val)) {
113+
continue;
114+
}
115+
M->addModuleFlag(ModuleFlag.Behavior, ModuleFlag.Key->getString(),
116+
ModuleFlag.Val);
117+
}
102118
}
103119

104120
// Set linkage of every external definition to linkonce_odr.

0 commit comments

Comments
 (0)