On Android GP register has been repurposed for SCS so there is no need to have .sdata section.
Could you add some justification for this change? It's fine to use .sdata in the absence of linker relaxation.
If Android doesn't want to see .sdata, then the motivation should be properly stated.
I think you might need to force it to 0. It looks like it might default to 8 in the backend.
lib/Target/RISCV/RISCVTargetObjectFile.h 20: unsigned SSThreshold = 8;
CodeGenOpts sets the default to 0:
clang/include/clang/Basic/CodeGenOptions.def /// The threshold to put data into small data section. VALUE_CODEGENOPT(SmallDataLimit, 32, 0)
... which should then be covered by the test.
Another possible direction is to revert the decision to make -msmall-data-threshold=8 the default (D57497).
GP relaxation users can set the option explicitly, or use a configuration file (e.g. place riscv64-unknown-linux-gnu-clang.cfg beside clang) to set this value to be larger than 0.
-fPIC defaulting to 0 seems rather weird.
Should you not be reusing this code and its behaviour?
/me notes this code is a bit of a mess, two duplicate blocks that should just be one block with a big condition...
Don't do this
This would be more in keeping with the existing code (replaces the Android check above too, consolidating it all in one place). Maybe also better to have this as the first if in the chain so it's more robust against future changes to the logic above.