Link time error when setting the VMA to address greater than 0x80000000

275 views
Skip to first unread message

sthiruva

unread,
May 5, 2016, 2:50:28 AM5/5/16
to RISC-V SW Dev
Hi,

I am trying to build an image which has a VMA of 0x8000_0000, but I get the following error.

c_test_riscv/high_c.cpp:7:(.text+0x30): relocation truncated to fit: R_RISCV_HI20 against `.LC0'



The code is as follows:

    #->cat high_c.cpp
    void something_something(const char *str)
    {
    }

    extern "C" void c_high()
    {
        something_something("and something");
    }



    #->cat linker.script
    ENTRY(c_high)
    SECTIONS
    {
        HIGH 0x80000000 : AT(0x1000){
            high_c.o (*)
        }
    }


The commands to build the code is:
#->cat compile.sh
riscv64-unknown-elf-g++ -ggdb -c high_c.cpp -o high_c.o
riscv64-unknown-elf-g++ -g -o test.elf -T linker.script -nostdlib high_c.o


Running this, give me the eror:

c_test_riscv/high_c.cpp:7:(.text+0x30): relocation truncated to fit: R_RISCV_HI20 against `.LC0'

Looks like the linker thinks that the symbol `.LC0' which I think points to the sting can be linked with a immediate load, but fails when the pointer is at a high address

Any pointers to fix this would be helpful

TIA,
sthiruva

PS: I do realise that this code will fail badly when run, but this is simplified code to demonstrate the issue

Michael Clark

unread,
May 5, 2016, 6:44:00 AM5/5/16
to sthiruva, RISC-V SW Dev
Hi,

Interesting.

I have had this error while working on some hand crafted asm. Likely the compiler is emitting a relative access that is overflowing the 20-bit relative primitive being emitted. Section distance. We successfully  tested placing RV64 at 8GB (0x2_0000_0000) so it's likely a section placement issue.

I am a). curious how that linker script syntax locates each section vs explicitly labelling each section address in the linker script as I am not familiar with that particular syntax. i.e. where are .text, .bss, .data and .rodata being located? If they are all located ~ 0x8000_0000 this should be okay. 

Can you compile with -S and emit the asm and perhaps try explicitly labelling the addresses for each section in the linker script?

The other issue is whether there is a need for larger mc models that use indirect references to span larger section distances. I believe x86 has -mcmodel=large to achieve this (for PIE code using RIP relative addressing).

Curious... I can experiment with this on the weekend when I have some spare time... I have a bit distracted by work to look on the RISC-V mailing list but will make time this weekend. The in memory ABI image is a problem I am quite interested in for various reasons (mostly hackers). I also have some other linker related observations to share...

Cheers.
Michael

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/40f2f2f2-055c-462e-b9b8-f3f96068008b%40groups.riscv.org.

sthiruva

unread,
May 5, 2016, 1:20:01 PM5/5/16
to RISC-V SW Dev, sha...@gmail.com

Michael Clark

unread,
May 5, 2016, 4:26:01 PM5/5/16
to sthiruva, RISC-V SW Dev
Ok good. Are you using some sucky web mailer that mucks up your formatting when you copy and paste but you can't see it on the screen when you send it? Your email formatting is all messed up (iCloud.com webmail SUCS). At least it doesn't mess with your grammar like Bryan does with mine. Also we used to use PINE, Elm or mutt which enforced 72-character width emails and top-posting (like this) was strictly prohibited. Patches were MIME encoded email messages piped from maildir directly to patch. Inline mailing list comments on patch fragments with > characters where used for code review. Guess we have GitHub pull request comments these days. Github has a nice UI.

Hope I don't get kick banned for misbehaving. The mailing list needs a code of conduct to keep people like me off it or behaving (better / more well / more nicely).

~mc

Sent from my iPhone

Shajid Thiruvathodi

unread,
May 6, 2016, 1:57:04 AM5/6/16
to Michael Clark, RISC-V SW Dev
Erm.. I was using the email composer at the google groups page( The red "POST REPLY" button).
This one I am composing using gmail.

This thread, I top posted. Next thread on it will be bottom posting. Promise! :)

-sthiruva

Richard Herveille

unread,
May 6, 2016, 2:31:06 AM5/6/16
to sthiruva, RISC-V SW Dev
Are these extra options specified somewhere? I'll have to add them to my Eclipse plugin. Is this for the Linux tool chain or the Newlib one?

Richard

Sent from my iPad
Reply all
Reply to author
Forward
0 new messages