[PATCH] D106300: [LangRef] Clarify comdat

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 19 12:06:25 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: rnk, sbc100, tejohnson.
Herald added subscribers: jdoerfert, sunfish, dschuff.
MaskRay requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

- ELF supports `noduplicates`.
- ELF calls the concept "section group". `GRP_COMDAT` emulates the PE COMDAT deduplication feature.
- "COMDAT group" is an ELF term. Avoid it for PE/COFF.
- WebAssembly supports comdat but only supports the `any` selection kind.
- A comdat must be included or omitted as a unit.
- A global object can be a member of at most one comdat.
- COFF requires a non-local linkage for non-`noduplicates` selection kinds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106300

Files:
  llvm/docs/LangRef.rst


Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -915,21 +915,24 @@
 Comdats
 -------
 
-Comdat IR provides access to COFF and ELF object file COMDAT functionality.
+Comdat IR provides access to object file COMDAT/section group functionality
+which represents interrelated sections.
 
-Comdats have a name which represents the COMDAT key. All global objects that
-specify this key will only end up in the final object file if the linker chooses
-that key over some other key. Aliases are placed in the same COMDAT that their
-aliasee computes to, if any.
+Comdats have a name which represents the COMDAT key and a selection kind to
+provide input on how the linker deduplicates comdats with the same key in two
+different object files. A comdat must be included or omitted as a unit.
+Discarding the whole comdat is allowed but discarding a subset is not.
 
-Comdats have a selection kind to provide input on how the linker should
-choose between keys in two different object files.
+A global object may be a member of at most one comdat. Aliases are placed in the
+same COMDAT that their aliasee computes to, if any.
 
 Syntax::
 
     $<Name> = comdat SelectionKind
 
-The selection kind must be one of the following:
+For selection kinds other than ``noduplicates``, only one of the duplicate
+comdats may be retained by the linker and the members of the remaining comdats
+must be discarded. The following selection kinds are supported:
 
 ``any``
     The linker may choose any COMDAT key, the choice is arbitrary.
@@ -939,15 +942,17 @@
 ``largest``
     The linker will choose the section containing the largest COMDAT key.
 ``noduplicates``
-    The linker requires that only section with this COMDAT key exist.
+    No deduplication is performed.
 ``samesize``
     The linker may choose any COMDAT key but the sections must contain the
     same amount of data.
 
-Note that XCOFF and the Mach-O platform don't support COMDATs, and ELF and
-WebAssembly only support ``any`` as a selection kind.
+- XCOFF and Mach-O don't support COMDATs.
+- COFF supports all selection kinds. Non-``noduplicates`` selection kinds need
+  a non-local linkage COMDAT symbol.
+- ELF supports ``any`` and ``noduplicates``. WebAssembly only supports ``any``.
 
-Here is an example of a COMDAT group where a function will only be selected if
+Here is an example of a COFF COMDAT where a function will only be selected if
 the COMDAT key's section is the largest:
 
 .. code-block:: text
@@ -966,7 +971,7 @@
 
   $foo = comdat any
   @foo = global i32 2, comdat
-
+  @bar = global i32 3, comdat($foo)
 
 In a COFF object file, this will create a COMDAT section with selection kind
 ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106300.359875.patch
Type: text/x-patch
Size: 2849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210719/34369769/attachment.bin>


More information about the llvm-commits mailing list