MobiVM / robovm

Ahead of time compiler for JVM bytecode targetting iOS, Mac OSX and Linux
https://mobivm.github.io
952 stars 132 forks source link

* fix: annotations are broken on 32 bit targets in 2.3.18 #676

Closed dkimitsa closed 2 years ago

dkimitsa commented 2 years ago

introduced in https://github.com/MobiVM/robovm/pull/639

root case

struct member alignment was wrongly calculated for jlong and double: was calculated as aligned by member size (8 bytes) but has to be 4 byte boundary.

code to reproduce

import java.lang.annotation.*;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@interface SampleAnnotation {
    long first();
    String last();
}

public class Test {
    @SampleAnnotation(first = 33, last = "last")
    private String myField;

    public void test() {
        try {
            Annotation[] anns = this.getClass().getDeclaredField("myField").getDeclaredAnnotations();
            for (Annotation a : anns) {
                System.out.println(((SampleAnnotation) a).first());
                System.out.println(((SampleAnnotation) a).last());
            }
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
    }
}

fix

use offsetof to get data layout offsets

dkimitsa commented 2 years ago

confirmed on ios7 32 bit

guillerodriguez commented 2 years ago

Does this impact the standard robovm library? Or is it only relevant if the app itself uses annotations ?

dkimitsa commented 2 years ago

@guillerodriguez there is some amount of annotations in cocoatouch -- these might be affected. in general you would already see lot of crashes in analytics

guillerodriguez commented 2 years ago

@guillerodriguez there is some amount of annotations in cocoatouch -- these might be affected. in general you would already see lot of crashes in analytics

So the latest usable official release is 2.3.16, right ? (since 2.3.17 is broken according to the changelog)

dkimitsa commented 2 years ago

if you need to support ios10 and bellow on 32 bit devices -- then yes