If .sdata is absent, linker synthesized __global_pointer$ gets a section index of SHN_ABS.
In -pie/-shared mode, lld complains if a PC relative relocation references an absolute symbol (SHN_ABS) but ld.bfd doesn't:
ld.lld: error: relocation R_RISCV_PCREL_HI20 cannot refer to lute symbol: __global_pointer$
To allow lla gp, __global_pointer$ when .sdata is absent, create a dummy .sdata .
Also, change the visibility from STV_HIDDEN to STV_DEFAULT and don't define the symbol for -shared.
This is what ld.bfd does, though I don't understand why it does so.