This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support for mapping symbol in RISCV.
Needs RevisionPublic

Authored by LiDongjin on Nov 4 2022, 5:38 AM.

Details

Summary

Support for mapping symbol in RISCV.

There are three types in mapping symbols: $d $x $x<isa>.
For $d and $x is same as ARM, So i just copy related codes and testcases
For $x<isa>, the content of isa must same as Tag_RISCV_arch.
When emit Tag_RISCV_arch attribute, The following codes must have $x<isa> mapping symbol.
Adjacent same Tag_RISCV_arch attribute do not need two$x<isa>.

Here we have two testcases: mapping-symbols.s and mapping-isa.s.
mapping-symbols.s about the $d and $x in different segment.
mapping-isa.s about $x<isa> in different attribute Tag_RISCV_arch.

The mapping symbol in riscv references:
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/196

Diff Detail

Event Timeline

LiDongjin created this revision.Nov 4 2022, 5:38 AM
Herald added a reviewer: MaskRay. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
LiDongjin requested review of this revision.Nov 4 2022, 5:38 AM
LiDongjin edited the summary of this revision. (Show Details)Nov 4 2022, 5:43 AM
LiDongjin removed reviewers: jhenderson, MaskRay.
LiDongjin retitled this revision from [RISCV] add mapping symbol to RISCV ELF. to [WIP] add mapping symbol to RISCV ELF..Nov 4 2022, 5:53 AM
LiDongjin retitled this revision from [WIP] add mapping symbol to RISCV ELF. to [WIP] [RISCV] add mapping symbol to RISCV ELF..
LiDongjin retitled this revision from [WIP] [RISCV] add mapping symbol to RISCV ELF. to [WIP] [RISCV] Support for mapping symbol in RISCV。.Nov 4 2022, 5:59 AM
LiDongjin updated this revision to Diff 473498.Nov 6 2022, 6:57 AM
LiDongjin retitled this revision from [WIP] [RISCV] Support for mapping symbol in RISCV。 to [WIP] [RISCV] Support for mapping symbol in RISCV..
LiDongjin edited the summary of this revision. (Show Details)
StephenFan added inline comments.Nov 6 2022, 7:17 PM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
296

The comment line should be deleted.

334

These comments should be deleted.

llvm/test/MC/RISCV/mapping-isa.s
2

Copy-paste from ARM?

StephenFan added inline comments.Nov 6 2022, 7:20 PM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
27

Do we need this header file?

LiDongjin updated this revision to Diff 473550.Nov 6 2022, 8:31 PM
LiDongjin edited the summary of this revision. (Show Details)
LiDongjin marked 4 inline comments as done.
LiDongjin edited the summary of this revision. (Show Details)Nov 6 2022, 9:45 PM
LiDongjin edited the summary of this revision. (Show Details)
LiDongjin retitled this revision from [WIP] [RISCV] Support for mapping symbol in RISCV. to [RISCV] Support for mapping symbol in RISCV..Nov 7 2022, 12:33 AM
LiDongjin edited the summary of this revision. (Show Details)Nov 7 2022, 12:47 AM
StephenFan added inline comments.Nov 7 2022, 7:00 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
118

It seems like 5 is a magic number.

LiDongjin added inline comments.Nov 7 2022, 6:03 PM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
118

It will change to RISCVAttrs::ARCH.

asb added a comment.Nov 8 2022, 2:40 AM

@kito-cheng, @jrtc27: I was wondering on if you could comment from a psABI workgroup perspective on the status of the mapping symbol proposal and the path to it becoming part of the standard?

The short summary is that there was a bunch of discussion about a year ago, things went quiet and nobody pushed it forward to get consensus and land it in the spec. I don't think there are outstanding technical reasons for that though, just that it wasn't prioritised and followed up on. Even if we did want to change it we're probably stuck with the current draft, anyway, since an implementation of it was merged in binutils a while ago despite that being bad practice for ABI things...

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
119–120

Can the moving of this please be split out into a separate patch? That makes it obvious what's changing and what's just moving.

kito-cheng added inline comments.Dec 16 2022, 7:51 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
220

"$x" + LastEMSInfo->ISAInfo + "", we didn't use < and > around arch string

LiDongjin updated this revision to Diff 487046.Jan 6 2023, 10:05 PM
LiDongjin added inline comments.Jan 6 2023, 10:06 PM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
118

Done

220

Done

LiDongjin updated this revision to Diff 487053.Jan 6 2023, 10:59 PM
LiDongjin updated this revision to Diff 487059.Jan 6 2023, 11:53 PM

LGTM, this match what we have in psABI PR and binutils implemention, but I would like to make sure @asb is happy with this too :)

asb added a comment.Jan 24 2023, 7:31 AM

LGTM, this match what we have in psABI PR and binutils implemention, but I would like to make sure @asb is happy with this too :)

I've not done a super in-depth review, but from a high-level look it seems good to me. Despite the fact binutils already supports this, I'd probably rather see the psABI change approved before landing this patch. Is it possible that might happen soon?

LGTM, this match what we have in psABI PR and binutils implemention, but I would like to make sure @asb is happy with this too :)

I've not done a super in-depth review, but from a high-level look it seems good to me. Despite the fact binutils already supports this, I'd probably rather see the psABI change approved before landing this patch. Is it possible that might happen soon?

Going to push this forward, hope this will happen soon, will notify here once it getting merged :)

@asb let you know psABI has merged the mapping symbol :)

@LiDongjin could you rebase this patch? it seems will result some conflict with current main branch, thanks :)

LiDongjin updated this revision to Diff 528696.EditedJun 5 2023, 11:31 PM

@kito-cheng rebase done .

LiDongjin updated this revision to Diff 528830.Jun 6 2023, 6:35 AM
LiDongjin updated this revision to Diff 528851.Jun 6 2023, 7:15 AM
This comment was removed by LiDongjin.
Joe added a subscriber: Joe.Jun 7 2023, 9:42 AM

The mapping symbol seems to be getting stripped out at the linker stage (either ld or lld), but I'm not sure why. Will continue to look into it.

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
268

Do we not need to set the State to something here? Otherwise the state never changes and an ISA mapping symbol will be generated for every instruction.

For example:

.attribute arch, "rv32i"
nop
nop
nop
nop

>

SYMBOL TABLE:
0000000000000000         *UND*  0000000000000000 $xrv32i2p1.0
0000000000000000         *UND*  0000000000000000 $xrv32i2p1.1
0000000000000000         *UND*  0000000000000000 $xrv32i2p1.2
0000000000000000         *UND*  0000000000000000 $xrv32i2p1.3
0000000000000000         *UND*  0000000000000000 $d.4
LiDongjin updated this revision to Diff 529523.Jun 8 2023, 1:25 AM

fix duplicate $x symbol for same isa attribute instructions.

Joe added inline comments.Jun 8 2023, 6:49 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
268

I think we need to assign the mapping symbol a location. This was the only way I was able to get the linker not to discard the symbol.

Example:

EmitMappingSymbol("$x" + LastEMSInfo->ISAInfo, SMLoc(),
    &getCurrentSectionOnly()->getDummyFragment(), 0);
LastEMSInfo->State = EMS_ISA;
279

By having the label suffixed by .n, gnu objdump interprets the last extension with the dot, leading to many warnings/errors. E.G cannot find default versions of the ISA extension zvl64b1p0.'`

It works if you remove the ., but equally you will get an error if you try and generate the same symbol twice.

Sorry I haven't got a solution for you, but I think it's definitely something that needs to be addressed.

Joe added inline comments.Jun 8 2023, 6:52 AM
llvm/test/MC/RISCV/mapping-isa.s
54

Probably should add a MAPPINGSYMBOLS-NOT check here and other palces, as this was not happening before your latest change, but the testing wasn't picking it up.

LiDongjin updated this revision to Diff 529905.Jun 9 2023, 4:17 AM
LiDongjin added inline comments.Jun 9 2023, 4:28 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
268

I try to fix the EmitMappingSymbol to use emitLabel. it works for assigning the mapping symbol a location.

279

Arm and aarch64 use the .n to distinguish the same symbol. I copy this solution to the riscv.
So how this case for arm and aarch64 to fix in the gnu objdum? thanks for any advice.

Fix some text cases in lld about the section labels.
if there are no symbols follow the section label, it will output the <section name>.
if we inserted the mapping symbols after the section label, it will output the <$x> or <$d>.

MaskRay requested changes to this revision.Aug 30 2023, 11:22 PM

Thanks for the patch. This needs rebase as mapping symbols have been implemented...

This revision now requires changes to proceed.Aug 30 2023, 11:22 PM