[ELF] Place _edata before .bss in the presence of .ldata

This minor issue is identified while working on #81224.

GitOrigin-RevId: 25cec33521ba1c67f5e939ceea277be18b2d0fb7
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index bd4db1e..5b7dfd3 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -1104,7 +1104,9 @@
 
   PhdrEntry *last = nullptr;
   PhdrEntry *lastRO = nullptr;
-
+  auto isLarge = [](OutputSection *osec) {
+    return config->emachine == EM_X86_64 && osec->flags & SHF_X86_64_LARGE;
+  };
   for (Partition &part : partitions) {
     for (PhdrEntry *p : part.phdrs) {
       if (p->p_type != PT_LOAD)
@@ -1124,10 +1126,11 @@
   }
 
   if (last) {
-    // _edata points to the end of the last mapped initialized section.
+    // _edata points to the end of the last non-large mapped initialized
+    // section.
     OutputSection *edata = nullptr;
     for (OutputSection *os : outputSections) {
-      if (os->type != SHT_NOBITS)
+      if (os->type != SHT_NOBITS && !isLarge(os))
         edata = os;
       if (os == last->lastSec)
         break;
diff --git a/test/ELF/x86-64-section-layout.s b/test/ELF/x86-64-section-layout.s
index f292877..0ba6053 100644
--- a/test/ELF/x86-64-section-layout.s
+++ b/test/ELF/x86-64-section-layout.s
@@ -43,7 +43,7 @@
 
 # CHECK:       0000000000201304     0 NOTYPE  GLOBAL DEFAULT [[#]] (.text)   _start
 # CHECK-NEXT:  0000000000201305     0 NOTYPE  GLOBAL DEFAULT [[#]] (.text)   _etext
-# CHECK-NEXT:  0000000000205b0a     0 NOTYPE  GLOBAL DEFAULT [[#]] (.ldata2) _edata
+# CHECK-NEXT:  0000000000203307     0 NOTYPE  GLOBAL DEFAULT [[#]] (.data)   _edata
 # CHECK-NEXT:  0000000000206d0b     0 NOTYPE  GLOBAL DEFAULT [[#]] (.lbss)   _end
 
 # CHECK1:      .data      PROGBITS        0000000000203306 000306 000001 00  WA  0   0  1
@@ -53,7 +53,7 @@
 
 # CHECK1:       0000000000201304     0 NOTYPE  GLOBAL DEFAULT [[#]] (.text)   _start
 # CHECK1-NEXT:  0000000000201305     0 NOTYPE  GLOBAL DEFAULT [[#]] (.text)   _etext
-# CHECK1-NEXT:  000000000020330a     0 NOTYPE  GLOBAL DEFAULT [[#]] (.ldata2) _edata
+# CHECK1-NEXT:  0000000000203307     0 NOTYPE  GLOBAL DEFAULT [[#]] (.data)   _edata
 # CHECK1-NEXT:  000000000020330a     0 NOTYPE  GLOBAL DEFAULT [[#]] (.ldata2) _end
 
 # CHECK2:      .note      NOTE            0000000000200300 000300 000001 00   A  0   0  1