[lld] [LLD][ELF] add bp-* options in ELF (PR #120514)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 08:52:01 PST 2025


================
@@ -0,0 +1,115 @@
+//===- BPSectionOrderer.cpp -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "BPSectionOrderer.h"
+#include "InputFiles.h"
+#include "InputSection.h"
+#include "SymbolTable.h"
+#include "Symbols.h"
+#include "lld/Common/BPSectionOrdererBase.inc"
+#include "llvm/Support/Endian.h"
+
+#define DEBUG_TYPE "bp-section-orderer"
+
+using namespace llvm;
+using namespace lld::elf;
+
+namespace {
+struct BPOrdererELF;
+}
+template <> struct lld::BPOrdererTraits<struct BPOrdererELF> {
+  using Section = elf::InputSectionBase;
+  using Symbol = elf::Symbol;
+};
+namespace {
+struct BPOrdererELF : lld::BPOrderer<BPOrdererELF> {
+  static uint64_t getSize(const Section &sec) { return sec.getSize(); }
+  static bool isCodeSection(const Section &sec) {
+    return sec.flags & llvm::ELF::SHF_EXECINSTR;
+  }
+  static SmallVector<Symbol *, 0> getSymbols(const Section &sec) {
+    SmallVector<Symbol *, 0> symbols;
+    for (auto *sym : sec.file->getSymbols())
+      if (auto *d = llvm::dyn_cast_or_null<Defined>(sym))
+        if (d->size > 0 && d->section == &sec)
+          symbols.emplace_back(d);
+    return symbols;
+  }
+
+  std::optional<StringRef> static getResolvedLinkageName(llvm::StringRef name) {
+    return name;
----------------
MaskRay wrote:

`return {}`. We don't expect the call sites to use it.

https://github.com/llvm/llvm-project/pull/120514


More information about the llvm-commits mailing list