From 0ba028411f505925b4ea31947cd67f2b0a502471 Mon Sep 17 00:00:00 2001 From: Peshkov Ivan Date: Wed, 6 Dec 2023 12:55:10 +0300 Subject: [PATCH 1/2] [RISCV] Fix linking with floating-point ABI Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I8K781 Signed-off-by: Lyupa Anastasia --- llvm/include/llvm/ObjCopy/CommonConfig.h | 3 +++ llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 4 ++++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 8 ++++++++ llvm/tools/llvm-objcopy/ObjcopyOpts.td | 2 ++ 4 files changed, 17 insertions(+) diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h index 4921f5281ca6..cd20eac444e9 100644 --- a/llvm/include/llvm/ObjCopy/CommonConfig.h +++ b/llvm/include/llvm/ObjCopy/CommonConfig.h @@ -218,6 +218,9 @@ struct CommonConfig { StringRef AllocSectionsPrefix; DiscardType DiscardMode = DiscardType::None; + // Float abi + Optional FabiValue; + // 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 781be3d8aeb1..2126324bbad9 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -604,6 +604,10 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig, Obj.OSABI = Config.OutputArch.value().OSABI; } + if (Config.FabiValue) { + Obj.Flags |= Config.FabiValue.value(); + } + 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 7db1e79f3e49..5baca1062a66 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -662,6 +662,14 @@ objcopy::parseObjcopyOptions(ArrayRef RawArgsArr, VisibilityStr.str().c_str()); } + if (InputArgs.hasArg(OBJCOPY_fabi_riscv)) { + StringRef FabiValue = InputArgs.getLastArgValue(OBJCOPY_fabi_riscv); + // TODO: check if this value is correct + uint32_t result; + FabiValue.getAsInteger(10, result); + Config.FabiValue = result; + } + 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 d3713b5ec3c3..a7e1f6b09c15 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -29,6 +29,8 @@ defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of " " with --add-symbol unless otherwise" " specified. The default value is 'default'.">; +defm fabi_riscv : Eq<"fabi-riscv", "Sets float ABI value for riscv arch">; + def compress_debug_sections : Joined<["--"], "compress-debug-sections=">, MetaVarName<"format">, -- Gitee From a510ba9728dc6f4f61ff8b6839fba5be59d2841d Mon Sep 17 00:00:00 2001 From: Lyupa Anastasia Date: Tue, 9 Jan 2024 16:18:19 +0300 Subject: [PATCH 2/2] [llvm-objcopy] Refactor fabi-riscv to elf-flags Signed-off-by: Lyupa Anastasia --- llvm/include/llvm/ObjCopy/CommonConfig.h | 6 ++++-- llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 6 ++++-- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 14 +++++++++----- llvm/tools/llvm-objcopy/ObjcopyOpts.td | 3 ++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h index cd20eac444e9..38132b725557 100644 --- a/llvm/include/llvm/ObjCopy/CommonConfig.h +++ b/llvm/include/llvm/ObjCopy/CommonConfig.h @@ -218,8 +218,10 @@ struct CommonConfig { StringRef AllocSectionsPrefix; DiscardType DiscardMode = DiscardType::None; - // Float abi - Optional FabiValue; + // OHOS_LOCAL begin + // Additional ELF object flags + Optional ELFObjFlags; + // OHOS_LOCAL end // Repeated options std::vector AddSection; diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp index 2126324bbad9..5c55abb72aed 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -604,9 +604,11 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig, Obj.OSABI = Config.OutputArch.value().OSABI; } - if (Config.FabiValue) { - Obj.Flags |= Config.FabiValue.value(); + // OHOS_LOCAL begin + if (Config.ELFObjFlags) { + Obj.Flags |= Config.ELFObjFlags.value(); } + // OHOS_LOCAL end if (!Config.SplitDWO.empty() && Config.ExtractDWO) { return Obj.removeSections( diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp index 5baca1062a66..cfacaa0aa030 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -662,13 +662,17 @@ objcopy::parseObjcopyOptions(ArrayRef RawArgsArr, VisibilityStr.str().c_str()); } - if (InputArgs.hasArg(OBJCOPY_fabi_riscv)) { - StringRef FabiValue = InputArgs.getLastArgValue(OBJCOPY_fabi_riscv); - // TODO: check if this value is correct + // OHOS_LOCAL begin + if (InputArgs.hasArg(OBJCOPY_elf_flags)) { + StringRef ELFObjFlags = InputArgs.getLastArgValue(OBJCOPY_elf_flags); uint32_t result; - FabiValue.getAsInteger(10, result); - Config.FabiValue = 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; diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td index a7e1f6b09c15..4c454d7ec59a 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -29,7 +29,8 @@ defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of " " with --add-symbol unless otherwise" " specified. The default value is 'default'.">; -defm fabi_riscv : Eq<"fabi-riscv", "Sets float ABI value for riscv arch">; +/// OHOS_LOCAL +defm elf_flags : Eq<"elf-flags", "Additional ELF flags of unsigned integer type">; def compress_debug_sections : Joined<["--"], "compress-debug-sections=">, -- Gitee