From: Nelson Chu <nelson.chu@sifive.com>
To: Fangrui Song <i@maskray.me>
Cc: Binutils <binutils@sourceware.org>,
James Clarke <jrtc27@jrtc27.com>,
Kito Cheng <kito.cheng@sifive.com>,
Palmer Dabbelt <palmerdabbelt@google.com>,
Jim Wilson <jimw@sifive.com>
Subject: Re: [PATCH 2/2] RISC-V: Support assembler modifier %got_pcrel_hi.
Date: Wed, 04 Mar 2020 01:54:00 -0000 [thread overview]
Message-ID: <CAJYME4GVAVawsdvMbhT0ckz_gfMsy+zoNNPcuCvPD2Ab4otMXQ@mail.gmail.com> (raw)
In-Reply-To: <20200304000721.ujbcawqjzv3eeweq@google.com>
Hi MaskRay,
On Wed, Mar 4, 2020 at 8:07 AM Fangrui Song <i@maskray.me> wrote:
>
> What if %got_pcrel_hi refers to a STB_LOCAL symbol? For example,
>
> auipc a0, %got_pcrel_hi(.L1)
>
> It may be worth a test.
>
> FWIW, llvm-mc -triple=riscv64 -filetype=obj a.s # create a R_RISCV_GOT_HI20 referencing .L1
> There is no special treatment.
Consider the following case tmp.s:
.option pic
.option norelax
.global foo
foo:
la a0, foo
.L1:
auipc a0, %got_pcrel_hi(foo)
ld a0, %pcrel_lo(.L1)(a0)
.L2:
auipc a0, %got_pcrel_hi(.L1)
addi a0, a0, %pcrel_lo(.L2)
la a0, .L1
$ ~/binutils-dev/build-elf64-upstream/build-install/bin/riscv64-unknown-elf-as
tmp.s -o tmp.o
$ ~/binutils-dev/build-elf64-upstream/build-install/bin/riscv64-unknown-elf-objdump
-dr tmp.o
tmp.o: file format elf64-littleriscv
Disassembly of section .text:
0000000000000000 <foo>:
0: 00000517 auipc a0,0x0
0: R_RISCV_GOT_HI20 foo
4: 00053503 ld a0,0(a0) # 0 <foo>
4: R_RISCV_PCREL_LO12_I .L0
0000000000000008 <.L1>:
8: 00000517 auipc a0,0x0
8: R_RISCV_GOT_HI20 foo
c: 00053503 ld a0,0(a0) # 8 <.L1>
c: R_RISCV_PCREL_LO12_I .L1
0000000000000010 <.L2>:
10: 00000517 auipc a0,0x0
10: R_RISCV_GOT_HI20 .L1
14: 00050513 mv a0,a0
14: R_RISCV_PCREL_LO12_I .L2
18: 00000517 auipc a0,0x0
18: R_RISCV_GOT_HI20 .L1
1c: 00053503 ld a0,0(a0) # 18 <.L2+0x8>
1c: R_RISCV_PCREL_LO12_I .L0
`foo` is a global symbol. `.L1` and `.L2` are local symbols. I think
the current upstream GNU assembler treats them all the same for LA
macro with pic and %got_pcrel_hi. So yes, the behavior should be the
same as llvm-mc. BTW I get the same result for the linux toolchain.
Thanks
Nelson
prev parent reply other threads:[~2020-03-04 1:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 10:22 [PATCH 0/2] Add description for the RISC-V relocatable modifiers in as doc Nelson Chu
2020-03-03 10:22 ` [PATCH 1/2] RISC-V: Add description for RISC-V Modifiers to " Nelson Chu
2020-03-03 22:12 ` Jim Wilson
2020-03-03 10:22 ` [PATCH 2/2] RISC-V: Support assembler modifier %got_pcrel_hi Nelson Chu
2020-03-03 22:16 ` Jim Wilson
2020-03-04 0:07 ` Fangrui Song
2020-03-04 1:54 ` Nelson Chu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJYME4GVAVawsdvMbhT0ckz_gfMsy+zoNNPcuCvPD2Ab4otMXQ@mail.gmail.com \
--to=nelson.chu@sifive.com \
--cc=binutils@sourceware.org \
--cc=i@maskray.me \
--cc=jimw@sifive.com \
--cc=jrtc27@jrtc27.com \
--cc=kito.cheng@sifive.com \
--cc=palmerdabbelt@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).