[lld] [LLD] Add CLASS syntax to SECTIONS (PR #95323)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 09:14:20 PDT 2024


================
@@ -198,13 +198,52 @@ the current location to a max-page-size boundary, ensuring that the next
 LLD will insert ``.relro_padding`` immediately before the symbol assignment
 using ``DATA_SEGMENT_RELRO_END``.
 
+Section Classes
+~~~~~~~~~~~~~~~
+
+``SECTIONS`` commands can define classes of input sections:
+
+::
+
+  SECTIONS {
+    CLASS(class_name) {
+      input-section-description
+      input-section-description
+      ...
+    }
+  }
+
+Input section descriptions can refer to a class using ``CLASS(class_name)``
+instead of the usual filename and section name patterns. For example:
+
+::
+
+  SECTIONS {
----------------
smithp35 wrote:

I'm assuming that CLASS(c) is within SECTIONS and not hoisted out of it so that input sections matching earlier input section descriptions don't match a CLASS with wildcards. For example:
```
SECTIONS {
  .rodata.first { specific_file.o(.rodata.earlier) }
  CLASS(c) { *(.rodata.earlier) }
  .rodata { *(.rodata) CLASS(c) (*.rodata.later) }
}
```
Although that could be worked around by defining a separate CLASS for specific_file.o(.rodata.earlier).

My hoisted syntax example
```
CLASSES {
  c1 { specific_file.o(.rodata.earlier) }
  c2 { *(.rodata.earlier) }
}
```
SECTIONS {
  .rodata.first { CLASS(c1) }
  .rodata { *(.rodata) CLASS(c2) (*.rodata.later) }
}
```

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


More information about the llvm-commits mailing list