[Nasm-bugs] [Bug 3392798] New: Wrong DW_AT_high_pc (sometimes)
noreply-nasm at dev.nasm.us
noreply-nasm at dev.nasm.us
Sat May 7 14:54:01 PDT 2022
https://bugzilla.nasm.us/show_bug.cgi?id=3392798
Bug ID: 3392798
Summary: Wrong DW_AT_high_pc (sometimes)
Product: NASM
Version: 2.15.xx
Hardware: All
OS: All
Status: OPEN
Severity: normal
Priority: Medium
Component: Assembler
Assignee: nobody at nasm.us
Reporter: simon.marchi at polymtl.ca
CC: chang.seok.bae at intel.com, gorcunov at gmail.com,
hpa at zytor.com, nasm-bugs at nasm.us
Obtained from: From OS distribution
Hi,
This bug originates from this one:
https://sourceware.org/bugzilla/show_bug.cgi?id=29128
On Ubuntu 20.04, using the tools distributed in the distro packages:
$ cat readfile.asm
global _start
section .text
_start: mov rax, 2
mov rdi, path
xor rsi, rsi
syscall
mov rax, 60
xor rdi, rdi
syscall
section .data
path: db "/etc/hosts", 0
$ nasm -f elf64 -F dwarf -g readfile.asm
$ nasm --version
NASM version 2.14.02
$ ld readfile.o -o readfile
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.34
$ llvm-dwarfdump-14 -F -color readfile
0x0000000b: DW_TAG_compile_unit
DW_AT_low_pc [DW_FORM_addr] (0x0000000000401000)
DW_AT_high_pc [DW_FORM_addr] (0x000000000040101e)
high_pc and low_pc are different, that's good.
If I try linking with a different linker:
$ ld.lld readfile.o -o readfile
$ llvm-dwarfdump-14 -F -color readfile
0x0000000b: DW_TAG_compile_unit
DW_AT_low_pc [DW_FORM_addr] (0x0000000000201160)
DW_AT_high_pc [DW_FORM_addr] (0x0000000000201160)
high_pc and low_pc are the same, that's not good.
Trying the same thing on Arch Linux:
$ nasm -f elf64 -F dwarf -g readfile.asm
$ nasm --version
NASM version 2.15.05 compiled on Sep 24 2020
$ ld readfile.o -o readfile
$ ld --version
GNU ld (GNU Binutils) 2.38
$ llvm-dwarfdump -F -color readfile
readfile: file format elf64-x86-64
.debug_info contents:
0x00000000: Compile Unit: length = 0x0000004a, format = DWARF32, version =
0x0003, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000004e)
0x0000000b: DW_TAG_compile_unit
DW_AT_low_pc [DW_FORM_addr] (0x0000000000401000)
DW_AT_high_pc [DW_FORM_addr] (0x0000000000401000)
The high and low pc are the same as well, not good.
I tried to dig into this, and I found that regardless of the nasm version or
platform (I tried with git master as well), the relocations for high_pc and
low_pc are always the same, `.text + 0`:
$ readelf --relocs readfile.o
Relocation section '.rela.debug_info' at offset 0x560 contains 5 entries:
Offset Info Type Symbol's Value
Symbol's Name + Addend
0000000000000006 000000050000000a R_X86_64_32 0000000000000000
.debug_abbrev + 0
000000000000000c 0000000200000001 R_X86_64_64 0000000000000000
.text + 0 ***
0000000000000014 0000000200000001 R_X86_64_64 0000000000000000
.text + 0 ***
000000000000001c 000000060000000a R_X86_64_32 0000000000000000
.debug_line + 0
000000000000003d 0000000200000001 R_X86_64_64 0000000000000000
.text + 0
I put some *** next to the ones I think are for low_pc and high_pc.
Seeing this, I don't understand why a linker would ever produce different
values for low_pc and high_pc, given the requested relocation is the same for
both fields. But clearly, the older ld on Ubuntu produces different values.
Any idea what's happening here? Was this relying on a old behavior of ld that
has now changed?
--
You are receiving this mail because:
You are on the CC list for the bug.
You are watching all bug changes.
More information about the Nasm-bugs
mailing list