On Fri, 30 Oct 2026 15:04:31 GMT, Jorn Vernee <[email protected]> wrote:

>> Currently we do not directly support unsigned types in the Linker. The 
>> javadoc has this to say about it:
>> 
>>>  A native linker typically does not provide canonical layouts for C's 
>>> unsigned integral
>>  types. Instead, they are modeled using the canonical layouts associated 
>> with their
>>  corresponding signed integral types. For instance, the C type `unsigned 
>> long`
>>  maps to the canonical layout for `code long`.
>> 
>> This was done under the earlier assumption that ABIs treat signed and 
>> unsigned types the same. However, it turns out that we missed certain cases 
>> where this does matter for some ABIs. More concretely:
>> 
>> - Mac x64 and AArch64 ABIs require integral types smaller than `int`  to be 
>> widened to `int` before being passed to a function 
>> [1](https://developer.apple.com/documentation/xcode/writing-64-bit-intel-code-for-apple-platforms),
>>  
>> [2](https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms).
>>  Clang even extends this behavior to Linux x64 (although this appears to be 
>> a bug) 
>> [3](https://mail.openjdk.org/archives/list/[email protected]/message/RJNMKNUXN7R5PSJETZKX3PMBJ7P6GYJG/).
>> - RISCV requires arguments smaller than XLEN to be extended to 32 bits 
>> according to their sign, and then sign extended to XLEN 
>> [4](https://docs.riscv.org/reference/abi/v1.0/riscv-cc-procedure-calling-convention.html).
>> - PowerPC requires small integer types (char, short, int, long, enum) to be 
>> extended to long 
>> [5](https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#PARAM-PASS).
>> 
>> In order to address these use cases we need to attach a bit of extra 
>> information to a linkage request that indicates the signedness of certain 
>> arguments. For this patch, we've chosen to attach that information directly 
>> to the argument layouts through a newly introduced `boolean isSigned()` 
>> method on a new `ValueLayout` subclass `OfIntegral` that is implemented by 
>> `OfByte`, `OfShort`, `OfInt`, and `OfLong`.
>> 
>> This information is potentially used by the linker to implement the correct 
>> extension. In cases where it doesn't affect the way functions are linker the 
>> information is erased in order to provide more efficient caching, since 
>> signed and unsigned types can share the same downcall handle in that case.
>> 
>> Testing: `jdk_foreign` test suite on Windows/Linux/Mac-x64, 
>> Mac/Linux-AArch64, Linux-x64 using the fallback linker.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](http...
>
> Jorn Vernee has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   re-add requires tag

I have seen test errors while running 
tools/sincechecker/modules/java.base/JavaBaseCheckSince.java:

src/java.base/java/lang/foreign/ValueLayout.java:255 method: 
java.lang.foreign.ValueLayout.OfByte 
java.lang.foreign.ValueLayout.OfByte.withSignedness(boolean): `@since` version: 
22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:333 method: 
java.lang.foreign.ValueLayout.OfShort 
java.lang.foreign.ValueLayout.OfShort.withSignedness(boolean): `@since` 
version: 22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:375 method: 
java.lang.foreign.ValueLayout.OfInt 
java.lang.foreign.ValueLayout.OfInt.withSignedness(boolean): `@since` version: 
22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:452 method: 
java.lang.foreign.ValueLayout.OfLong 
java.lang.foreign.ValueLayout.OfLong.withSignedness(boolean): `@since` version: 
22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:142 class: 
java.lang.foreign.ValueLayout.OfIntegral: `@since` version: 22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:147 method: boolean 
java.lang.foreign.ValueLayout.OfIntegral.isSigned(): `@since` version: 22; 
should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:155 method: 
java.lang.foreign.ValueLayout.OfIntegral 
java.lang.foreign.ValueLayout.OfIntegral.withSignedness(boolean): `@since` 
version: 22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:160 method: 
java.lang.foreign.ValueLayout.OfIntegral 
java.lang.foreign.ValueLayout.OfIntegral.withName(java.lang.String): `@since` 
version: 22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:166 method: 
java.lang.foreign.ValueLayout.OfIntegral 
java.lang.foreign.ValueLayout.OfIntegral.withoutName(): `@since` version: 22; 
should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:173 method: 
java.lang.foreign.ValueLayout.OfIntegral 
java.lang.foreign.ValueLayout.OfIntegral.withByteAlignment(long): `@since` 
version: 22; should be: 28
src/java.base/java/lang/foreign/ValueLayout.java:179 method: 
java.lang.foreign.ValueLayout.OfIntegral 
java.lang.foreign.ValueLayout.OfIntegral.withOrder(java.nio.ByteOrder): 
`@since` version: 22; should be: 28

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33417#issuecomment-6574130855

Reply via email to