Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple write example #746

Closed
Cr0a3 opened this issue Aug 30, 2024 · 3 comments · Fixed by #747
Closed

Simple write example #746

Cr0a3 opened this issue Aug 30, 2024 · 3 comments · Fixed by #747

Comments

@Cr0a3
Copy link

Cr0a3 commented Aug 30, 2024

Hi,
I tried the simple write example: https://github.com/gimli-rs/gimli/blob/master/crates/examples/src/bin/simple_write.rs
I ran it, got the object file.
Then when i tried to compile it into an executable i got following errors:

PS C:\Users\toni-\Desktop\gimli_test> gcc hello.o 
hello.o:hello.c:(.debug_line+0x22): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_line_str'
hello.o:hello.c:(.debug_line+0x2c): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_line_str'
hello.o:hello.c:(.debug_line+0x31): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_line_str'
hello.o:hello.c:(.debug_info+0x8): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_abbrev'
hello.o:hello.c:(.debug_info+0x31): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_rnglists'
hello.o:hello.c:(.debug_info+0x35): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_line'
collect2.exe: error: ld returned 1 exit status

So i gone ahed and changched the format from Dwarf32 to Dwarf64. This time the linking actually worked. But then as i gone to test it in gdb. I got following error:

Dwarf Error: bad offset (0x140010000) in compilation unit header (offset 0x0 + 6) [in module C:\Users\toni-\Desktop\gimli_test\a.exe]

My gcc is:

gcc.exe (MinGW-W64 x86_64-msvcrt-posix-seh) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Bye

@Cr0a3
Copy link
Author

Cr0a3 commented Aug 30, 2024

The error is only under windows (i tested it under linux and it worked fine)

@philipc
Copy link
Collaborator

philipc commented Aug 30, 2024

It's using the wrong relocation kind. I never tested it under windows. It needs to be RelocationKind::SectionOffset for references to other DWARF sections (so for RelocationTarget::Section the resulting relocation type is IMAGE_REL_AMD64_SECREL). You still need to use IMAGE_REL_AMD64_ADDR64 for RelocationTarget::Symbol.

Changing to Dwarf64 is the wrong way to try to fix this. That is only needed when the DWARF sections are large. It has nothing to do with address size.

In general, when something like this doesn't work, the easiest way to figure out why it should be doing is to look at what gcc or clang generate.

@Cr0a3
Copy link
Author

Cr0a3 commented Aug 30, 2024

Thank you that I fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants