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

Daniel Thornburgh via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 15:13:38 PDT 2024


================
@@ -0,0 +1,379 @@
+# REQUIRES: x86
+
+# RUN: rm -rf %t && split-file %s %t && cd %t
+
+# RUN: llvm-mc -n -filetype=obj -triple=x86_64 matching.s -o matching.o
+
+## CLASS definitions match sections in linker script order. The sections may be
+## placed in a different order. Classes may derive from one another, and class
+## references may be restricted by INPUT_SECTION_FLAGS.
+
+# RUN: ld.lld -T matching.ld matching.o -o matching
+# RUN: llvm-readobj -x .rodata matching | FileCheck %s --check-prefix=MATCHING
+
+# MATCHING: 02030104
+
+
+## An error is reported when a section class has more than one description.
+
+# RUN: not ld.lld -T already-defined.ld matching.o 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ALREADY-DEFINED --implicit-check-not=error:
+
+# ALREADY-DEFINED: error: already-defined.ld:3: section class 'a' already defined
+
+
+## An error is reported when a filename pattern is missing in a section class
+## description.
+
+# RUN: not ld.lld -T missing-filename-pattern.ld matching.o 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=MISSING-FILENAME-PATTERN --implicit-check-not=error:
+
+# MISSING-FILENAME-PATTERN: error: missing-filename-pattern.ld:2: expected filename pattern
+
+
+## An error is reported when the content of section classes is demanded before
+## input sections have been assigned to them.
+
+# RUN: not ld.lld -T used-before-assigned.ld matching.o 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=USED-BEFORE-ASSIGNED
+
+# USED-BEFORE-ASSIGNED: error: section class 'a' used before assigned
----------------
mysterymath wrote:

Yeah, I see the ambiguity; "used before [sections] assigned [to class}" vs "used before [class] assigned [to output section]". "Defined" works well instead.

I had been using "reference" for the relationship between an output section and a class, since it doesn't really change that the section is "assigned" to the class. The final assignment occurs only after spilling has finished. Changed the error accordingly. 

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


More information about the llvm-commits mailing list