summaryrefslogtreecommitdiff
path: root/ld/testsuite
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2023-02-16 16:27:08 +0000
committerNick Clifton <nickc@redhat.com>2023-02-16 16:27:08 +0000
commit9fe129a4105bb59398f73ce96938a94f19265b79 (patch)
tree33772b47038b290b37158f78813bab4ce8360958 /ld/testsuite
parent6f63b61dd116becf96f47bb2dec61edd59f88a08 (diff)
Add support for the ASCII directive inside linker scripts.
* ldlex.l: Add ASCII token. * ldgram.y: Add parsing of the ASCII command. * ldlang.c (lang_add_string): Add maximum size parameter. Move escape character handling code into separate function. * ldlang.h (lang_add_string): Update prototype. * NEWS: Mention the new feature. * ld.texi (Output Section Data): Document the new directives. * testsuite/ld-scripts/asciz.t: Adjust to work on more architectures and to test more aspects of the ASCIZ directive. * testsuite/ld-scripts/asciz.d: Adjust to match the changes to the test linker script. * testsuite/ld-scripts/ascii.d: New test driver. * testsuite/ld-scripts/ascii.s: New test assembler source. * testsuite/ld-scripts/ascii.t: New test script. * testsuite/ld-scripts/script.exp: Run the new test.
Diffstat (limited to 'ld/testsuite')
-rw-r--r--ld/testsuite/ld-scripts/ascii.d25
-rw-r--r--ld/testsuite/ld-scripts/ascii.s11
-rw-r--r--ld/testsuite/ld-scripts/ascii.t38
-rw-r--r--ld/testsuite/ld-scripts/asciz.d19
-rw-r--r--ld/testsuite/ld-scripts/asciz.t23
-rw-r--r--ld/testsuite/ld-scripts/script.exp1
6 files changed, 91 insertions, 26 deletions
diff --git a/ld/testsuite/ld-scripts/ascii.d b/ld/testsuite/ld-scripts/ascii.d
new file mode 100644
index 00000000000..cfc1a4cbdba
--- /dev/null
+++ b/ld/testsuite/ld-scripts/ascii.d
@@ -0,0 +1,25 @@
+#source: ascii.s
+#ld: -T ascii.t
+#objdump: -s -j .header
+#notarget: [is_aout_format]
+#skip: tic4x-*-* tic54x-*-* *-*-*ecoff *-*-macho *-*-aix*
+
+.*: file format .*
+
+Contents of section .header:
+ .... 70726f67 72616d20 6e616d65 00000000 program name....
+ .... 656d7074 79000000 00000000 00000000 empty...........
+ .... 00000000 00000000 00000000 00000000 ................
+ .... 00000000 00000000 00000000 00000000 ................
+ .... 00000000 00000000 00000000 00000000 ................
+ .... 636f6d6d 656e7420 310a0000 00000000 comment 1.......
+ .... 00000000 00000000 00000000 00000000 ................
+ .... 636f6d6d 656e7420 320a0000 00000000 comment 2.......
+ .... 00000000 00000000 00000000 00000000 ................
+ .... 636f6d6d 656e7420 330a0000 00000000 comment 3.......
+ .... 00000000 00000000 00000000 00000000 ................
+ .... 636f6d6d 656e7420 340a0000 00000000 comment 4.......
+ .... 00000000 00000000 49206d65 616e7420 ........I meant
+ .... 746f2073 61793a20 54686973 20697320 to say: This is
+ .... 77617920 746f6f20 6c6f6e67 00000000 way too long....
+#pass
diff --git a/ld/testsuite/ld-scripts/ascii.s b/ld/testsuite/ld-scripts/ascii.s
new file mode 100644
index 00000000000..a1b6148dc79
--- /dev/null
+++ b/ld/testsuite/ld-scripts/ascii.s
@@ -0,0 +1,11 @@
+ .extern ecc_start
+ .section .text
+main:
+ .long 0x45444F43
+ .long 0x12345678
+
+ .section .data
+ .long 0x9abcdef0
+
+ .section .bss
+ .long 0
diff --git a/ld/testsuite/ld-scripts/ascii.t b/ld/testsuite/ld-scripts/ascii.t
new file mode 100644
index 00000000000..6f682fabd38
--- /dev/null
+++ b/ld/testsuite/ld-scripts/ascii.t
@@ -0,0 +1,38 @@
+_start = 0x000000;
+
+SECTIONS
+{
+ . = 0x1000 + SIZEOF_HEADERS;
+
+ .header ALIGN (0x100) (READONLY) :
+ {
+ ASCII (16) "program name"
+ ASCII (64) "empty"
+ ASCII (4 * 8) "comment 1\n"
+ ASCII (32) "comment 2\n"
+ ASCII (32) "comment 3\n"
+ ASCII (24) "comment 4\n"
+ ASCII (64) "I meant to say: This is way too long"
+ }
+
+ .text ALIGN (0x100) :
+ {
+ entry = .;
+ *(.text)
+ }
+
+ .data : AT (0x400000)
+ {
+ *(.data)
+ }
+
+ . = ALIGN(0x20);
+
+ .bss :
+ {
+ *(.bss)
+ }
+
+ /DISCARD/ : { *(*) }
+}
+
diff --git a/ld/testsuite/ld-scripts/asciz.d b/ld/testsuite/ld-scripts/asciz.d
index 615cf99732f..75e3c858a07 100644
--- a/ld/testsuite/ld-scripts/asciz.d
+++ b/ld/testsuite/ld-scripts/asciz.d
@@ -1,17 +1,14 @@
#source: asciz.s
#ld: -T asciz.t
-#objdump: -s -j .text
-#target: [is_elf_format]
-#skip: mips*-*-*
-#skip: tilegx*-*-* tilepro-*-*
-# COFF, PE and MIPS targets align code to a 16 byte boundary
-# tilegx andtilepro aligns code to a 8 byte boundary.
+#objdump: -s -j .data
+#notarget: [is_aout_format]
+#skip: tic4x-*-* tic54x-*-* *-*-*ecoff *-*-macho *-*-aix*
.*: file format .*
-Contents of section .text:
- .... 01010101 54686973 20697320 61207374 ....This is a st
- .... 72696e67 00...... ........ ........ ring............
- .... 54686973 20697320 616e6f74 68657220 This is another
- .... 0a737472 696e6753 00 .stringS........
+Contents of section .data:
+ .... 54686973 20697320 61207374 72696e67 This is a string
+ .... 00546869 73206973 20616e6f 74686572 .This is another
+ .... 0a537472 696e6700 006e6f71 756f7465 .String..noquote
+ .... 7300 s.
#pass
diff --git a/ld/testsuite/ld-scripts/asciz.t b/ld/testsuite/ld-scripts/asciz.t
index ab66f9a5bfb..3aeb7d0c767 100644
--- a/ld/testsuite/ld-scripts/asciz.t
+++ b/ld/testsuite/ld-scripts/asciz.t
@@ -1,23 +1,16 @@
-MEMORY {
- rom : ORIGIN = 0x00000, LENGTH = 0x10000
- ram : ORIGIN = 0x10000, LENGTH = 0x10000
-}
_start = 0x000000;
SECTIONS
{
. = 0x1000 + SIZEOF_HEADERS;
- .text ALIGN (0x20) :
- {
- *(.text)
+
+ .data : AT (0x10000)
+ {
ASCIZ "This is a string"
- . = ALIGN(0x20);
- align_label = .;
- ASCIZ "This is another \nstring\123"
- unalign_label = .;
- }
- .data : AT (0x10000) { *(.data) } >ram /* NO default AT>rom */
- . = ALIGN(0x20);
- .bss : { *(.bss) } >ram /* NO default AT>rom */
+ ASCIZ "This is another\n\123tring"
+ ASCIZ ""
+ ASCIZ noquotes
+ }
+
/DISCARD/ : { *(*) }
}
diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
index a574dde034c..56e12da8e61 100644
--- a/ld/testsuite/ld-scripts/script.exp
+++ b/ld/testsuite/ld-scripts/script.exp
@@ -228,6 +228,7 @@ foreach test_script $test_script_list {
}
run_dump_test "asciz"
+run_dump_test "ascii"
run_dump_test "align-with-input"
run_dump_test "pr20302"
run_dump_test "output-section-types"