[llvm] [llvm-objcopy] Add --change-section-address (PR #98664)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 01:47:36 PDT 2024


================
@@ -191,6 +152,61 @@ struct NewSectionInfo {
   std::shared_ptr<MemoryBuffer> SectionData;
 };
 
+// Flags set by --set-section-flags or --rename-section. Interpretation of these
+// is format-specific and not all flags are meaningful for all object file
+// formats. This is a bitmask; many section flags may be set.
+enum SectionFlag {
+  SecNone = 0,
+  SecAlloc = 1 << 0,
+  SecLoad = 1 << 1,
+  SecNoload = 1 << 2,
+  SecReadonly = 1 << 3,
+  SecDebug = 1 << 4,
+  SecCode = 1 << 5,
+  SecData = 1 << 6,
+  SecRom = 1 << 7,
+  SecMerge = 1 << 8,
+  SecStrings = 1 << 9,
+  SecContents = 1 << 10,
+  SecShare = 1 << 11,
+  SecExclude = 1 << 12,
+  SecLarge = 1 << 13,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SecLarge)
+};
+
+struct SectionRename {
+  StringRef OriginalName;
+  StringRef NewName;
+  std::optional<SectionFlag> NewFlags;
+};
+
+struct SectionFlagsUpdate {
+  StringRef Name;
+  SectionFlag NewFlags;
+};
+
+struct AddressUpdate {
+  uint64_t Value = 0;
+  bool Absolute = false;
+  bool Negative = false;
+};
----------------
jh7370 wrote:

I'll admit that I don't have much experience using `APInt`. I can see it has a `getZExtValue` to convert to a `uint64_t`, so you could do your calculations using `APInt` exclusively until you needed the actual value (at which point you could check for overflow and report an error), or something like that. However, I imagine it could end up a bit messy.

The enum option would at least make the booleans easier to handle, I feel.

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


More information about the llvm-commits mailing list