diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h index 4921f5281ca63f6339a19dff0baed2f192ccff0c..38132b725557841d380c216b0fdf30b72f84b57e 100644 --- a/llvm/include/llvm/ObjCopy/CommonConfig.h +++ b/llvm/include/llvm/ObjCopy/CommonConfig.h @@ -218,6 +218,11 @@ struct CommonConfig { StringRef AllocSectionsPrefix; DiscardType DiscardMode = DiscardType::None; + // OHOS_LOCAL begin + // Additional ELF object flags + Optional ELFObjFlags; + // OHOS_LOCAL end + // Repeated options std::vector AddSection; std::vector DumpSection; diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp index 781be3d8aeb1c836eb641c7725b77bf52a916bee..5c55abb72aeda739ad5d5f5a765bd41eb2a5164c 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -604,6 +604,12 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig, Obj.OSABI = Config.OutputArch.value().OSABI; } + // OHOS_LOCAL begin + if (Config.ELFObjFlags) { + Obj.Flags |= Config.ELFObjFlags.value(); + } + // OHOS_LOCAL end + if (!Config.SplitDWO.empty() && Config.ExtractDWO) { return Obj.removeSections( ELFConfig.AllowBrokenLinks, diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp index 7db1e79f3e49a1b017bdd9d6705026845bb33752..cfacaa0aa030d65724aac20fbd2341a86db8ff95 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -662,6 +662,18 @@ objcopy::parseObjcopyOptions(ArrayRef RawArgsArr, VisibilityStr.str().c_str()); } + // OHOS_LOCAL begin + if (InputArgs.hasArg(OBJCOPY_elf_flags)) { + StringRef ELFObjFlags = InputArgs.getLastArgValue(OBJCOPY_elf_flags); + uint32_t result; + if (ELFObjFlags.getAsInteger(10, result)) + return createStringError(errc::invalid_argument, + "'%s' is not a valid ELF object flags value", + ELFObjFlags.str().c_str()); + Config.ELFObjFlags = result; + } + // OHOS_LOCAL end + for (const auto *Arg : InputArgs.filtered(OBJCOPY_subsystem)) { StringRef Subsystem, Version; std::tie(Subsystem, Version) = StringRef(Arg->getValue()).split(':'); diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td index d3713b5ec3c32ff16623d81ac4aa1175d6dc7db3..4c454d7ec59a4cd71031b1d795bdbfb8fe15f6a4 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -29,6 +29,9 @@ defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of " " with --add-symbol unless otherwise" " specified. The default value is 'default'.">; +/// OHOS_LOCAL +defm elf_flags : Eq<"elf-flags", "Additional ELF flags of unsigned integer type">; + def compress_debug_sections : Joined<["--"], "compress-debug-sections=">, MetaVarName<"format">,