[lld] 309d1c4 - [ELF][test] Add a test to demonstrate #66836

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 09:04:46 PDT 2023


Author: Fangrui Song
Date: 2023-09-20T09:04:41-07:00
New Revision: 309d1c43bd034276203d21ec214346ae588b0b63

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

LOG: [ELF][test] Add a test to demonstrate #66836

Added: 
    lld/test/ELF/linkerscript/locationcountererr-arm-exidx.test

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/linkerscript/locationcountererr-arm-exidx.test b/lld/test/ELF/linkerscript/locationcountererr-arm-exidx.test
new file mode 100644
index 000000000000000..4dd7ae05d067416
--- /dev/null
+++ b/lld/test/ELF/linkerscript/locationcountererr-arm-exidx.test
@@ -0,0 +1,62 @@
+# REQUIRES: arm
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=armv7-linux-gnueabi a.s -o a.o
+
+## If we don't merge adjacent duplicate entries, __code_size will be negative and
+## . += __code_size will trigger a "move location counter backward" error.
+## LLD may report more errors further down, but there is only one "move location counter backward" error.
+# RUN: not ld.lld -z norelro -z max-page-size=4096 -T a.t a.o -o /dev/null --no-merge-exidx-entries 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ERR --implicit-check-not=error:
+
+# ERR:      error: a.t:14: unable to move location counter backward for: code.unused_space
+# ERR-NEXT: error: a.t:9: unable to move location counter backward for: dummy1
+# ERR-NEXT: error: a.t:10: unable to move location counter backward for: dummy2
+# ERR-NEXT: error: a.t:14: unable to move location counter backward for: code.unused_space
+# ERR-NEXT: error: a.t:9: unable to move location counter backward for: dummy1
+# ERR-NEXT: error: a.t:10: unable to move location counter backward for: dummy2
+# ERR-NEXT: error: a.t:14: unable to move location counter backward for: code.unused_space
+# ERR-NEXT: error: section dummy1 at 0x1000 of size 0xFFFFFFFFFFFFFF6C exceeds available address space
+# ERR-NEXT: error: section dummy2 at 0x2000 of size 0xFFFFFFFFFFFFFF6C exceeds available address space
+# ERR-NEXT: error: section code.unused_space at 0x4104 of size 0xFFFFFFFFFFFFFF6C exceeds available address space
+
+## If we merge adjacent duplicate entries, we will have enough space. Don't report
+## a spurious error https://github.com/llvm/llvm-project/issues/66836
+# RUN: not ld.lld -z norelro -z max-page-size=4096 -T a.t a.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
+
+# ERR2: error: a.t:14: unable to move location counter backward for: code.unused_space
+
+#--- a.s
+.globl _start
+_start:
+  bx lr
+
+.macro A
+.section .text.f\@,"ax"
+.globl f\@
+f\@:
+.fnstart
+  bx lr
+.cantunwind
+.fnend
+.endm
+
+.rept 20
+  A
+.endr
+
+#--- a.t
+MEMORY {
+  DUMMY1 (RW) : ORIGIN = 0x1000, LENGTH = 0x70
+  DUMMY2 (RW) : ORIGIN = 0x2000, LENGTH = 0x70
+  CODE (RX) : ORIGIN = 0x4000, LENGTH = 0x70
+}
+code_end = ORIGIN(CODE) + LENGTH(CODE);
+
+SECTIONS {
+  dummy1 (NOLOAD) : { . += code_size; } > DUMMY1
+  dummy2 (NOLOAD) : { . += code_size; } > DUMMY2
+  .text : { *(.text .text.*) } > CODE
+  .ARM.exidx : { *(.ARM.exidx .ARM.exidx.*) } > CODE
+  code_size = code_end - .;
+  code.unused_space (NOLOAD) : { . += code_size; } > CODE
+}


        


More information about the llvm-commits mailing list