https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94134
Bug ID: 94134 Summary: pdp11-aout puts initial variable into .text section rather than .data Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: casner at acm dot org Target Milestone: --- The assembler output for a C program compiled for the pdp11-aout target begins with a .text directive. If that program begins with a variable that is not initialized to a nonzero value, that variable will be left if the .text section rather than being allocated to the .data section. If the first variable is initialized to a nonzero value, then a .data directive is inserted after the .text directive to switch sections. This bug matters for formats where the text section is read-only or with split instruction and data spaces. I selected component target, but I don't know if this problem is specific to the pdp11-aout target. Here is a simple example showing this problem: Command: pdp11-aout-gcc -ffreestanding -nostdlib -S -o zero.s zero.c static int zero = 0; static int one = 1; int main() {} .text .even _zero: .=.+ 02 .data .even _one: .word 01 .text .even .globl _main _main: setd seti mov r5,-(sp) mov sp,r5 jsr pc,___main nop mov (sp)+,r5 rts pc If the first variable is initialized to a nonzero value, the output is correct: Command: pdp11-aout-gcc -ffreestanding -nostdlib -S -o one.s one.c static int one = 1; static int zero = 0; int main() {} .text .data .even _one: .word 01 .even _zero: .=.+ 02 .text .even .globl _main _main: setd seti mov r5,-(sp) mov sp,r5 jsr pc,___main nop mov (sp)+,r5 rts pc My environment is a macOS host and pdp11-aout target. GNU C17 (GCC) version 10.0.1 20200303 (experimental) (pdp11-aout) compiled by GNU C version 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17), GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.20-GMP Configured with: ../configure --target=pdp11-aout --prefix=/usr/local --disable-libstdc++-v3 --disable-libssp --disable-libgfortran --disable-libobjc --disable-libbacktrace --with-gmp=/opt/local/ --with-mpfr=/opt/local/ --with-mpc=/opt/local/