This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Generate PIC address sequence for medany -fno-pic
AbandonedPublic

Authored by MaskRay on Jan 1 2020, 10:49 AM.

Details

Reviewers
None

Event Timeline

MaskRay created this revision.Jan 1 2020, 10:49 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 1 2020, 10:49 AM
jrtc27 added a comment.EditedJan 1 2020, 11:04 AM

I am still of the view that we should support rewriting the instruction stream in the linker when necessary like BFD does. We need to do this to be able to link in GCC-compiled code, including libraries. It is a very simple thing to do with a patch available that provides consistency between the GNU world and the LLVM world.

llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
680

This is confusing and differs from when you invoke the assembler manually, even via the Clang driver with the right code model specified. Any las there will be assembled as AUIPC/ADDI. I am of the view it was a mistake to make la's behaviour conditional on PICness and it should have always used the GOT, but this is what we have.

llvm/lib/Target/TargetMachine.cpp
192

Are we sure we want to do this and take the performance hit over GCC due to the extra level of indirection on every single extern global access? If this is the solution to take for extern weak, I think we should limit it to just that and have a separate discussion about non-extern-weak.

I am still of the view that we should support rewriting the instruction stream in the linker when necessary like BFD does. We need to do this to be able to link in GCC-compiled code, including libraries. It is a very simple thing to do with a patch available that provides consistency between the GNU world and the LLVM world.

https://github.com/riscv/riscv-elf-psabi-doc/issues/126#issuecomment-570076329

MaskRay marked 2 inline comments as done.Jan 1 2020, 11:30 AM
MaskRay added a subscriber: bsdjhb.
MaskRay added inline comments.
llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
680

I am of the view it was a mistake to make la's behaviour conditional on PICness and it should have always used the GOT, but this is what we have.

I agree with you. la's behavior should not be conditional on PIC. RISC-V probably should have a GOT relaxation mechanism. See my comment at https://github.com/riscv/riscv-elf-psabi-doc/issues/126

llvm/lib/Target/TargetMachine.cpp
192

I'd like to know more about -mcmodel=medany -fno-pic's use cases. I guess @bsdjhb's FreeBSD kernel use case can probably be met by -mcmodel=medany -fpie.

I think there is no precedent which differs extern-strong and extern-weak. If GOT relaxation works, we can make this unconditional.

// RISC-V prefer avoiding copy relocations.
if (TT.isRISCV()
  return false;
jrtc27 added inline comments.Jan 1 2020, 11:41 AM
llvm/lib/Target/TargetMachine.cpp
192

It can, but that implies GOT accesses for anything extern, which will hurt kernel performance.

MaskRay abandoned this revision.May 3 2022, 10:34 AM
rkruppe removed a subscriber: rkruppe.May 3 2022, 11:58 AM