xref: /llvm-project-15.0.7/lld/test/ELF/linkerscript/alternate-sections.s (revision 052d95a6)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3# RUN: echo "SECTIONS { abc : { *(foo) *(bar) *(zed) } }" > %t.script
4# RUN: ld.lld -o %t --script %t.script %t.o -shared
5# RUN: llvm-readobj -s -section-data %t | FileCheck %s
6
7# This test shows an oddity in lld. When a linker script alternates among
8# different types of output section in the same command, the sections are
9# reordered.
10# In this test we go from regular, to merge and back to regular. The reason
11# for the reordering is that we need two create two output sections and
12# one cannot be in the middle of another.
13# If this ever becomes a problem, some options would be:
14# * Adding an extra layer in between input section and output sections (Chunk).
15#   With that this example would have 3 chunks, but only one output section.
16#   This would unfortunately complicate the non-script case too.
17# * Just create three output sections.
18# * If having three output sections causes problem, have linkerscript specific
19#   code to write the section table and section indexes. That way we could
20#   keep 3 sections internally but not expose that.
21
22# CHECK: Name: abc
23# CHECK: 0000: 01000000 00000000 02000000 00000000  |
24# CHECK: Name: abc
25# CHECK: 0000: 61626331 323300                      |abc123.|
26
27        .section foo, "a"
28        .quad 1
29
30        .section bar,"aMS",@progbits,1
31        .asciz  "abc123"
32
33        .section zed, "a"
34        .quad 2
35

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026