From fc738b99d4d5ad4e1a584c3f09b119a7134395c2 Mon Sep 17 00:00:00 2001 From: lzy Date: Wed, 11 Jun 2025 17:16:11 +0800 Subject: [PATCH] compiler & openEuler oeaware schedule opt --- lld/ELF/Config.h | 1 + lld/ELF/Driver.cpp | 1 + lld/ELF/SyntheticSections.cpp | 13 +++++++++++++ lld/ELF/SyntheticSections.h | 15 +++++++++++++++ lld/ELF/Writer.cpp | 1 + lld/test/ELF/oeaware.s | 17 +++++++++++++++++ 6 files changed, 48 insertions(+) create mode 100644 lld/test/ELF/oeaware.s diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 28726d48e428..4a2bf3476a3c 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -338,6 +338,7 @@ struct Config { uint8_t zStartStopVisibility; bool zText; bool zRetpolineplt; + int8_t zOeawarePolicy; bool zWxneeded; DiscardPolicy discard; GnuStackKind zGnustack; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index eb6734dfd458..f874a41cd087 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1501,6 +1501,7 @@ static void readConfigs(opt::InputArgList &args) { config->zStartStopVisibility = getZStartStopVisibility(args); config->zText = getZFlag(args, "text", "notext", true); config->zWxneeded = hasZOption(args, "wxneeded"); + config->zOeawarePolicy = args::getZOptionValue(args, OPT_z, "oeaware-policy", -1); setUnresolvedSymbolPolicy(args); config->power10Stubs = args.getLastArgValue(OPT_power10_stubs_eq) != "no"; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 41053c647275..78efef830af0 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4922,8 +4922,21 @@ template void elf::createSyntheticSections() { add(*in.shStrTab); if (in.strTab) add(*in.strTab); + if (config->zOeawarePolicy != -1) { + in.oeaware = std::make_unique(); + add(*in.oeaware); + } +} + +void OeAware::writeTo(uint8_t *buf) { + if (config->zOeawarePolicy != -1) + write32(buf, config->zOeawarePolicy); } +size_t OeAware::getSize() const { return 4; } + +void OeAware::finalizeContents() {} + InStruct elf::in; std::vector elf::partitions; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index d4169e1e1aca..8f11ad2b7648 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -1425,6 +1425,20 @@ private: SmallVector symbols; }; +class OeAware : public SyntheticSection { +public: + OeAware() + : SyntheticSection(llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE, + llvm::ELF::SHT_NOTE, /*alignment=*/4, ".LLVM4OE_oeAware") + {} + void writeTo(uint8_t *buf) override; + size_t getSize() const override; + void finalizeContents() override; + +private: + uint64_t size; +}; + template void createSyntheticSections(); InputSection *createInterpSection(); MergeInputSection *createCommentSection(); @@ -1512,6 +1526,7 @@ struct InStruct { std::unique_ptr strTab; std::unique_ptr symTab; std::unique_ptr symTabShndx; + std::unique_ptr oeaware; void reset(); }; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 8e3a746a08eb..e22037f31c9e 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1961,6 +1961,7 @@ template void Writer::finalizeSections() { llvm::TimeTraceScope timeScope("Finalize synthetic sections"); finalizeSynthetic(in.bss.get()); + finalizeSynthetic(in.oeaware.get()); finalizeSynthetic(in.bssRelRo.get()); finalizeSynthetic(in.symTabShndx.get()); finalizeSynthetic(in.shStrTab.get()); diff --git a/lld/test/ELF/oeaware.s b/lld/test/ELF/oeaware.s new file mode 100644 index 000000000000..50f66c228a34 --- /dev/null +++ b/lld/test/ELF/oeaware.s @@ -0,0 +1,17 @@ +# REQUIRES: target=aarch64{{.*}} +# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o +# RUN: ld.lld %t.o -o %ta -z oeaware-policy=1 +# RUN: llvm-objdump -j .LLVM4OE_oeAware %ta -d | FileCheck %s + +# CHECK: <.LLVM4OE_oeAware>: +# CHECK-NEXT: 00000001 + +# RUN: ld.lld %t.o -o %tb -z oeaware-policy=2 +# RUN: llvm-objdump -j .LLVM4OE_oeAware %tb -d | FileCheck %s --check-prefix=OPTION + +# OPTION: <.LLVM4OE_oeAware>: +# OPTION-NEXT: 00000002 + +.globl _start +_start: nop +.bss; .byte 0 -- Gitee