Skip to content

Incorrect linker script symbol value due to layout reiteration #468

@parth-07

Description

@parth-07

In some cases, layout reiteration that happens in eld causes incorrect linker script symbol value. This happens because layout reiteration causes reevaluation of some assignments with newer symbol values than what they should use.

Reproducer:

#!/usr/bin/env bash

cat >1.c <<\EOF
int foo() { return 1; }

int val = 3;
EOF


cat > script.t << '!'
u = 0x100;
SECTIONS {
  v = u;
  .text : { *(.text*) }
  u = 0x300;
  .data : { *(.data*) }
}
!


LDs=(ld.eld)
SFs=(eld)

clang -o 1.o --target=riscv64-unknown-elf 1.c -c -ffunction-sections

for i in "${!SFs[@]}"; do
  ${LDs[$i]} -o 1.${SFs[$i]}.out 1.o -T script.t -Map 1.${SFs[$i]}.map.txt
done

llvm-readelf -s 1.eld.out | grep 'ABS v'
EOF

**Output**

13: 0000000000000300 0 NOTYPE GLOBAL DEFAULT ABS v


The expected value of `v` is 0x100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions