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

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 09:14:09 PST 2023


https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/75495

Spotted by Alexandre Ganea in #75407.

>From 9c777ce7bcaa6a548f7f8a5e6dcaa8e26eebe589 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Thu, 14 Dec 2023 18:09:19 +0100
Subject: [PATCH] [LLD][COFF] Fix ARM64 EC chunks comparator.

Spotted by Alexandre Ganea in #75407.
---
 lld/COFF/Writer.cpp                |  2 +-
 lld/test/COFF/arm64ec-codemap.test | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

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