[lld] b1cc6f7 - [LLD][COFF] Fix ARM64 EC chunks comparator. (#75495)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 14:05:33 PST 2023


Author: Jacek Caban
Date: 2023-12-14T23:05:29+01:00
New Revision: b1cc6f778d9ba419cbfb205bc49b433d5ff23a29

URL: https://github.com/llvm/llvm-project/commit/b1cc6f778d9ba419cbfb205bc49b433d5ff23a29
DIFF: https://github.com/llvm/llvm-project/commit/b1cc6f778d9ba419cbfb205bc49b433d5ff23a29.diff

LOG: [LLD][COFF] Fix ARM64 EC chunks comparator. (#75495)

Spotted by Alexandre Ganea in #75407.

Added: 
    

Modified: 
    lld/COFF/Writer.cpp
    lld/test/COFF/arm64ec-codemap.test

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 89e0f5b2df7441..4eeb6ba804bdfe 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1480,7 +1480,7 @@ void Writer::sortECChunks() {
       llvm::stable_sort(sec->chunks, [=](const Chunk *a, const Chunk *b) {
         std::optional<chpe_range_type> aType = a->getArm64ECRangeType(),
                                        bType = b->getArm64ECRangeType();
-        return !aType || (bType && *aType < *bType);
+        return bType && (!aType || *aType < *bType);
       });
   }
 }

diff  --git a/lld/test/COFF/arm64ec-codemap.test b/lld/test/COFF/arm64ec-codemap.test
index da3a4f9e47292c..7f4d5d84b458e1 100644
--- a/lld/test/COFF/arm64ec-codemap.test
+++ b/lld/test/COFF/arm64ec-codemap.test
@@ -5,6 +5,7 @@ RUN: llvm-mc -filetype=obj -triple=arm64-windows arm64-func-sym.s -o arm64-func-
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-func-sym.s -o arm64ec-func-sym.obj
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows arm64ec-func-sym2.s -o arm64ec-func-sym2.obj
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows data-sec.s -o data-sec.obj
+RUN: llvm-mc -filetype=obj -triple=arm64ec-windows data-sec2.s -o data-sec2.obj
 RUN: llvm-mc -filetype=obj -triple=arm64ec-windows empty-sec.s -o arm64ec-empty-sec.obj
 RUN: llvm-mc -filetype=obj -triple=x86_64-windows x86_64-func-sym.s -o x86_64-func-sym.obj
 RUN: llvm-mc -filetype=obj -triple=x86_64-windows empty-sec.s -o x86_64-empty-sec.obj
@@ -119,8 +120,8 @@ DISASMM-NEXT: 18000200d: c3                           retq
 
 Merging data sections into code sections causes data to be separated from the code when sorting chunks.
 
-RUN: lld-link -out:testdm.dll -machine:arm64ec arm64ec-func-sym.obj x86_64-func-sym.obj \
-RUN:          data-sec.obj loadconfig-arm64ec.obj -dll -noentry -merge:.testdata=.text -merge:.rdata=test
+RUN: lld-link -out:testdm.dll -machine:arm64ec arm64ec-func-sym.obj x86_64-func-sym.obj data-sec.obj \
+RUN:          data-sec2.obj loadconfig-arm64ec.obj -dll -noentry -merge:.testdata=.text -merge:.rdata=test
 
 RUN: llvm-readobj --coff-load-config testdm.dll | FileCheck -check-prefix=CODEMAPDM %s
 CODEMAPDM:      CodeMap [
@@ -135,6 +136,8 @@ DISASMDM:      Disassembly of section .text:
 DISASMDM-EMPTY:
 DISASMDM-NEXT: 0000000180001000 <.text>:
 DISASMDM-NEXT: 180001000: 00000001     udf     #0x1
+DISASMDM-NEXT: 180001004: 00000000     udf     #0x0
+DISASMDM-NEXT: 180001008: 00000002     udf     #0x2
 DISASMDM-NEXT:                 ...
 DISASMDM-NEXT: 180002000: 52800040     mov     w0, #0x2
 DISASMDM-NEXT: 180002004: d65f03c0     ret
@@ -254,6 +257,10 @@ x86_64_func_sym2:
     .section .testdata, "rd"
     .xword 1
 
+#--- data-sec2.s
+    .section .testdata, "rd"
+    .xword 2
+
 #--- empty-sec.s
     .section .empty1, "xr"
     .section .empty2, "xr"


        


More information about the llvm-commits mailing list