https://sourceware.org/bugzilla/show_bug.cgi?id=33159
Bug ID: 33159 Summary: RISC-V:Output Section LMA Alignment Product: binutils Version: 2.46 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: bigmagicreadsun at gmail dot com Target Milestone: --- During the linking phase, the linker fails to properly align the LMA according to section alignment rules (ALIGN). Here is my test case: /* test.S */ .section .text, "ax", @progbits .align 6 .global _func1 _func1: li a0, 0x1234 jal _func2 jal _func3 j . .section .text2, "ax", @progbits .align 6 .global _func2 _func2: jal _func3 j . .section .text3, "ax", @progbits .align 6 .global _func3 _func3: .word 0x1111 .word 0x2222 .word 0x3333 .word 0x4444 .word 0x5555 .word 0x6666 .word 0x7777 j . Linker script: /* linker.ld */ OUTPUT_ARCH("riscv") ENTRY(_func1) MEMORY { ROM (rxa!w) : ORIGIN = 0x100000, LENGTH = 64K RAM (rxa!w) : ORIGIN = 0x200000, LENGTH = 64K } SECTIONS { .text : { *(.text) } >RAM AT>ROM .text2 : { *(.text2) } >RAM AT>ROM .text3 : { *(.text3) } >RAM AT>ROM _text_lma = LOADADDR(.text); _text2_lma = LOADADDR(.text2); _text3_lma = LOADADDR(.text3); } Compilation command: riscv64-unknown-elf-clang -O0 -march=rv32imac -mabi=ilp32 -T linker.ld test.S -nostartfiles Resulting ELF section information from: riscv64-unknown-elf-objdump -h a.out a.out: file format elf32-littleriscv Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000042 00200000 00100000 00001000 2**6 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .text2 00000042 00200080 00100042 00001080 2**6 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .text3 00000042 00200100 00100084 00001100 2**6 CONTENTS, ALLOC, LOAD, READONLY, CODE 3 .riscv.attributes 0000004c 00000000 00000000 00001142 2**0 CONTENTS, READONLY It can be observed that the LMA is not properly aligned, and this behavior significantly differs from what clang produces. Here are the clang compilation results for comparison: a.out: file format elf32-littleriscv Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000010 00200000 00100000 00001000 2**6 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .text2 00000006 00200040 00100040 00001040 2**6 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .text3 0000001e 00200080 00100080 00001080 2**6 CONTENTS, ALLOC, LOAD, READONLY, CODE 3 .riscv.attributes 00000032 00000000 00000000 0000109e 2**0 CONTENTS, READONLY 4 .comment 00000079 00000000 00000000 000010d0 2**0 CONTENTS, READONLY I would like to confirm whether this design behavior is intentional/enhancement-or-bug? -- You are receiving this mail because: You are on the CC list for the bug.