From 14f8442d241188909f3a50082260808c9769582b Mon Sep 17 00:00:00 2001 From: jiangning Date: Tue, 10 Jun 2025 15:15:16 +0800 Subject: [PATCH] compiler & OS oeaware schedule opt --- lld/ELF/Config.h | 1 + lld/ELF/Driver.cpp | 2 ++ lld/ELF/SyntheticSections.cpp | 9 +++++++++ lld/ELF/SyntheticSections.h | 15 +++++++++++++++ lld/ELF/Writer.cpp | 6 ++++++ lld/test/ELF/oeaware.s | 17 +++++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 lld/test/ELF/oeaware.s diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 94af8c34beb7..abd9bcf9dc4f 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -317,6 +317,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 e65dfa553de0..7bf2361e1b72 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -569,6 +569,7 @@ constexpr const char *knownZFlags[] = { "text", "undefs", "wxneeded", + "oe-aware", }; static bool isKnownZFlag(StringRef s) { @@ -1397,6 +1398,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 de25750bf9eb..8238cc330276 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -3900,6 +3900,15 @@ size_t PackageMetadataNote::getSize() const { alignTo(config->packageMetadata.size() + 1, 4); } +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 38d0c80a073d..6215019cc587 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -1245,6 +1245,20 @@ public: size_t getSize() const override; }; +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; +}; + InputSection *createInterpSection(); MergeInputSection *createCommentSection(); template void splitSections(); @@ -1323,6 +1337,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 dd37bbbf76c1..33a1046767b0 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -294,6 +294,11 @@ template void elf::createSyntheticSections() { in.bss = std::make_unique(".bss", 0, 1); add(*in.bss); + if (config->zOeawarePolicy != -1) { + in.oeaware = std::make_unique(); + add(*in.oeaware); + } + // If there is a SECTIONS command and a .data.rel.ro section name use name // .data.rel.ro.bss so that we match in the .data.rel.ro output section. // This makes sure our relro is contiguous. @@ -2067,6 +2072,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