Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relocations in .text on arm #16369

Closed
radekdoulik opened this issue Aug 20, 2019 · 11 comments · Fixed by #16432 or #16729
Closed

Relocations in .text on arm #16369

radekdoulik opened this issue Aug 20, 2019 · 11 comments · Fixed by #16432 or #16729

Comments

@radekdoulik
Copy link
Contributor

@radekdoulik radekdoulik commented Aug 20, 2019

It looks like AOT compiler produces shared libraries on XA/arm, which contains relocations in .text section.

Discussed it with @vargaz on slack and he thinks it was introduced recently by 9ff3b0d

I have tried older XA d16.1 and it indeed didn't contain relocations in .text, while current XA with mono-2019-06 does.

d16.1:

arm-linux-androideabi-readelf  -a /Users/rodo/git/monodroid-samples/android5.0/Topeka/Topeka/obj/Release/aot/armeabi-v7a/libaot-Topeka.dll.so |grep TEXT

Relevant part of source

.text 1
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#function
bl .Lm_0
bl .Lm_1
bl .Lm_2
...

No relocations in .text:

Section Headers:
...
  [ 5] .text             PROGBITS        00000240 000240 022a30 00  AX  0   0 16
...
Relocation section '.rel.dyn' at offset 0x178 contains 24 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00024008  00000017 R_ARM_RELATIVE   
0002401c  00000017 R_ARM_RELATIVE   
00024020  00000017 R_ARM_RELATIVE   
00024024  00000017 R_ARM_RELATIVE   
00024028  00000017 R_ARM_RELATIVE   
0002402c  00000017 R_ARM_RELATIVE   
00024030  00000017 R_ARM_RELATIVE   
00024034  00000017 R_ARM_RELATIVE   
00024038  00000017 R_ARM_RELATIVE   
0002403c  00000017 R_ARM_RELATIVE   
00024040  00000017 R_ARM_RELATIVE   
00024044  00000017 R_ARM_RELATIVE   
0002404c  00000017 R_ARM_RELATIVE   
00024050  00000017 R_ARM_RELATIVE   
00024054  00000017 R_ARM_RELATIVE   
00024058  00000017 R_ARM_RELATIVE   
0002405c  00000017 R_ARM_RELATIVE   
0002407c  00000017 R_ARM_RELATIVE   
00024080  00000017 R_ARM_RELATIVE   
00024084  00000017 R_ARM_RELATIVE   
00024088  00000017 R_ARM_RELATIVE   
0002408c  00000017 R_ARM_RELATIVE   
00024090  00000017 R_ARM_RELATIVE   
00024094  00000017 R_ARM_RELATIVE   

master (which uses mono-2019-06):

arm-linux-androideabi-readelf  -a /Users/rodo/git/monodroid-samples/android5.0/Topeka/Topeka/obj/Release-master/aot/armeabi-v7a/libaot-Topeka.dll.so |grep TEXT
 0x00000016 (TEXTREL)                    0x0
 0x0000001e (FLAGS)                      TEXTREL

Relevant part of source:

.text 1
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#function
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
ldr pc,=.Lm_2

Relocations in .text

Section Headers:
...
  [ 5] .text             PROGBITS        00001580 001580 022e78 00  AX  0   0 16
...
Relocation section '.rel.dyn' at offset 0x178 contains 640 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00020fe4  00000017 R_ARM_RELATIVE   
00020fec  00000017 R_ARM_RELATIVE   
00020ff4  00000017 R_ARM_RELATIVE   
00020ffc  00000017 R_ARM_RELATIVE
...

This probably affects the performance and will potentially cause problems on Android as the shared libs should not contain .text relocations on API >= 23. (https://android-developers.googleblog.com/2016/06/android-changes-for-ndk-developers.html)

@grendello

This comment has been minimized.

Copy link
Member

@grendello grendello commented Aug 20, 2019

The requirement for the DSO not to contain text relocations will become a problem with the upcoming Android Q, which will enforce (with SELinux) the requirement and AOT-ed apps will, therefore, stop working there.

@akoeplinger

This comment has been minimized.

Copy link
Member

@akoeplinger akoeplinger commented Aug 20, 2019

/cc @lewurm

Note that #14043 was backported to 2019-02.

@lewurm

This comment has been minimized.

Copy link
Member

@lewurm lewurm commented Aug 21, 2019

So I see two solutions to this problem:

  1. We keep it like it is right now, support larger assemblies on arm32 with AOT but it won't work on Android Q. The reason why we need those relocations is that GNU ld errors out on too large offsets. Unfortunately the AOT compiler can't know with what offsets the linker will end up. FWIW on iOS the linker is smart enough to insert branch islands.
  2. We revert all those changes introduced for "big assemblies".

I'm voting for 2) because

  • Big assemblies are not that common (basically you refuse to use the IL linker for some reason).
  • The suggested workaround would be to switch to arm64 or don't use AOT if you really care about big assemblies.

Does that sound good @radekdoulik @grendello ?

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 21, 2019

Can you not output 32bit relative link-time constant addresses?
What do large C/C++ programs do?
I should experiment..

@radekdoulik

This comment has been minimized.

Copy link
Contributor Author

@radekdoulik radekdoulik commented Aug 21, 2019

  1. sounds good to me, if we don't find other solution.

Couldn't we try to generate the branch islands ourselves? How do they look, wouldn't they also introduce relocations?

@grendello

This comment has been minimized.

Copy link
Member

@grendello grendello commented Aug 22, 2019

  1. sounds good for now

@radekdoulik branch islands are basically interim locations within the branch limit range that let the program jump between two distant locations exceeding the limit. They shouldn't introduce relocations.

@radekdoulik

This comment has been minimized.

Copy link
Contributor Author

@radekdoulik radekdoulik commented Aug 22, 2019

Well, I am not sure as this llvm test looks like it expects the linker to create branch island and relocation as well. I don't know that much about it, so thus asking :-) https://github.com/microsoft/llvm-1/blob/master/test/MC/MachO/ARM/long-call-branch-island-relocation.s

@grendello

This comment has been minimized.

Copy link
Member

@grendello grendello commented Aug 23, 2019

I should have been more clear - they shouldn't create .text relocations (which is what we're trying to avoid)

@lewurm linker on iOS is GNU ld.gold right? Or is it ldd? In either case, we're dealing with similar tooling as the NDK Is currently clang-only + ld.gold/ldd, so I suppose it should be possible to get the same functionality out of the linker on Android as on iOS? Or did you mean the dynamic linker on the runtime?

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 23, 2019

Apple linker is ancient GNU ld fork I believe.

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 23, 2019

I don't think we are in a position to create branch islands.
I think it belongs in a linker.
I think it'd involve interleaving just enough extra .text and .rdata sections (instead of one each), so that each neighbor is reachable from anywhere in each neighbor. So that there is always .rdata reachable from .text, and so that .rdata contains full pointers, relocations.
It'd require a global view, that a linker has.
But maybe I'm way off.

@lewurm

This comment has been minimized.

Copy link
Member

@lewurm lewurm commented Aug 23, 2019

Jay is right, we (the AOT compiler) do not have the necessary information to emit branch islands. We could, but that requires a lot of work and in the end would make us a linker :-)

iOS uses ld64. Whatever that is, but it doesn't seem to be ld.gold. The mentioned test by @radekdoulik is specifically for MachO, so it's using the Apple specific linker. The last time I tried for Android (a couple months ago), its linker did not automatically generate branch islands and I also didn't find any hints for it in the documentation.

monojenkins added a commit that referenced this issue Aug 26, 2019
[android] remove text relocations in AOT/arm32

Remove support for "big assemblies" for AOT on Android running on ARM 32bit. This will remove relocations in `.text` which are not allowed in the upcoming Android Q release anymore.

_If_ a customer should run into this problem, the suggested workarounds are:
* Switch to ARM64, or
* Do not use AOT compilation.

Fixes #16369
@marek-safar marek-safar added this to the 2019-06 (6.4.xx) milestone Sep 4, 2019
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Sep 4, 2019
Changes: mono/mono@2c3aeaf...7af64d1

Upstream-Fixes: mono/mono#16369
Fixes? #3366
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Sep 5, 2019
Changes: mono/mono@2c3aeaf...7af64d1

Upstream-Fixes: mono/mono#16369
Fixes? #3366

Context: #3579
monojenkins added a commit that referenced this issue Sep 10, 2019
…cations (#16729)

[aot] move method_addresses to data.rel.so section to avoid text relocations

Another revert of a revert! 🎉 

After some discussions with @grendello and @radekdoulik, we came up with this solution. It's a better attempt to fix #16369 as it (1) works within the restrictions of Android 10 and (2) still works for armv7 AOT. 


`.text` relocations aren't allowed in Android 10 (and this change shouldn't hurt on Linux).

AOT compilation:
```console
$ MONO_PATH=/Users/lewurm/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/ \
MONO_ENV_OPTIONS="" \
./sdks/out/android-cross-arm-release/bin/armv7-linux-android-mono-sgen \
--aot=keep-temps,outfile=here.dll.so,asmwriter,mtriple=armv7-linux-gnueabi,tool-prefix=/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-,ld-flags= \
~/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll

Mono Ahead of Time compiler - compiling assembly /Users/lewurm/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll
AOTID 7DDD05DA-37E0-813A-8C27-3E1634391BB3
Compiled: 144382/144382
Executing the native assembler: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-as"   -mfpu=vfp3 -o /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ.o /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ
Executing the native linker: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld"  -shared -o here.dll.so.tmp  /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ.o
Stripping the binary: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip" --strip-symbol=\$a --strip-symbol=\$d here.dll.so.tmp
Retained input file.
JIT time: 15031 ms, Generation time: 7374 ms, Assembly+Link time: 75130 ms.
```

Before:
```console
$ grep -C 6 'method_addresses:' /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ
        .align 3
jit_code_end:

        .byte 0,0,0,0
.text 1
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#function
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
$ arm-linux-androideabi-readelf -a here.dll.so | grep -i textrel
 0x00000016 (TEXTREL)                    0x0
 0x0000001e (FLAGS)                      TEXTREL
```

After switching to `.data.rel.so`:
```console
$ grep -C 6 'method_addresses:' /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_1YhAgn  # assembly file produced by AOT compiler
jit_code_end:

        .byte 0,0,0,0
.section ".data.rel.ro"
.subsection 0
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#object
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
$ arm-linux-androideabi-readelf -a here.dll.so | grep -i textrel
$ echo $?
1
```
monojenkins added a commit that referenced this issue Sep 10, 2019
… text relocations (#16751)

[2019-08] [aot] move method_addresses to data.rel.so section to avoid text relocations

Another revert of a revert! 🎉 

After some discussions with @grendello and @radekdoulik, we came up with this solution. It's a better attempt to fix #16369 as it (1) works within the restrictions of Android 10 and (2) still works for armv7 AOT. 


`.text` relocations aren't allowed in Android 10 (and this change shouldn't hurt on Linux).

AOT compilation:
```console
$ MONO_PATH=/Users/lewurm/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/ \
MONO_ENV_OPTIONS="" \
./sdks/out/android-cross-arm-release/bin/armv7-linux-android-mono-sgen \
--aot=keep-temps,outfile=here.dll.so,asmwriter,mtriple=armv7-linux-gnueabi,tool-prefix=/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-,ld-flags= \
~/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll

Mono Ahead of Time compiler - compiling assembly /Users/lewurm/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll
AOTID 7DDD05DA-37E0-813A-8C27-3E1634391BB3
Compiled: 144382/144382
Executing the native assembler: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-as"   -mfpu=vfp3 -o /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ.o /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ
Executing the native linker: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld"  -shared -o here.dll.so.tmp  /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ.o
Stripping the binary: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip" --strip-symbol=\$a --strip-symbol=\$d here.dll.so.tmp
Retained input file.
JIT time: 15031 ms, Generation time: 7374 ms, Assembly+Link time: 75130 ms.
```

Before:
```console
$ grep -C 6 'method_addresses:' /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ
        .align 3
jit_code_end:

        .byte 0,0,0,0
.text 1
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#function
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
$ arm-linux-androideabi-readelf -a here.dll.so | grep -i textrel
 0x00000016 (TEXTREL)                    0x0
 0x0000001e (FLAGS)                      TEXTREL
```

After switching to `.data.rel.so`:
```console
$ grep -C 6 'method_addresses:' /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_1YhAgn  # assembly file produced by AOT compiler
jit_code_end:

        .byte 0,0,0,0
.section ".data.rel.ro"
.subsection 0
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#object
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
$ arm-linux-androideabi-readelf -a here.dll.so | grep -i textrel
$ echo $?
1
```

Backport of #16729.

/cc @lewurm
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Dec 3, 2019
Changes: mono/api-snapshot@fc50bc4...45a61d9

        $ git diff --shortstat fc50bc4f...45a61d93
         22 files changed, 775 insertions(+), 474 deletions(-)

Changes: mono/cecil@a6c8f5e...a6a7f5c

        $ git diff --shortstat a6c8f5e1...a6a7f5c0
         55 files changed, 818 insertions(+), 530 deletions(-)

Changes: mono/corefx@1f87de3...49f1c45

        $ git diff --shortstat e4f7102b...49f1c453
         38 files changed, 1171 insertions(+), 419 deletions(-)

Changes: mono/linker@ebe2a1f...e8d054b

        $ git diff --shortstat ebe2a1f4...e8d054bf
         137 files changed, 5360 insertions(+), 1781 deletions(-)

Changes: mono/mono@8946e49...18920a8

        $ git diff --shortstat 8946e49a...18920a83
         1811 files changed, 47240 insertions(+), 48331 deletions(-)

Changes: xamarin/xamarin-android-api-compatibility@a61271e...50a3c52

        $ git diff --shortstat a61271e0...50a3c52d
         1 file changed, 2 insertions(+), 791 deletions(-)

Fixes: #3619

Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1005448
Context: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/967582
Context: dotnet/coreclr#26370
Context: dotnet/coreclr#26479
Context: dotnet/corefx#40455
Context: dotnet/corefx#40578
Context: mono/mono#7377
Context: mono/mono#12421
Context: mono/mono#12586
Context: mono/mono#14080
Context: mono/mono#14725
Context: mono/mono#14772
Context: mono/mono#15261
Context: mono/mono#15262
Context: mono/mono#15263
Context: mono/mono#15307
Context: mono/mono#15308
Context: mono/mono#15310
Context: mono/mono#15646
Context: mono/mono#15687
Context: mono/mono#15805
Context: mono/mono#15992
Context: mono/mono#15994
Context: mono/mono#15999
Context: mono/mono#16032
Context: mono/mono#16034
Context: mono/mono#16046
Context: mono/mono#16192
Context: mono/mono#16308
Context: mono/mono#16310
Context: mono/mono#16369
Context: mono/mono#16380
Context: mono/mono#16381
Context: mono/mono#16395
Context: mono/mono#16411
Context: mono/mono#16415
Context: mono/mono#16486
Context: mono/mono#16570
Context: mono/mono#16605
Context: mono/mono#16616
Context: mono/mono#16689
Context: mono/mono#16701
Context: mono/mono#16712
Context: mono/mono#16742
Context: mono/mono#16759
Context: mono/mono#16803
Context: mono/mono#16808
Context: mono/mono#16824
Context: mono/mono#16876
Context: mono/mono#16879
Context: mono/mono#16918
Context: mono/mono#16943
Context: mono/mono#16950
Context: mono/mono#16974
Context: mono/mono#17004
Context: mono/mono#17017
Context: mono/mono#17038
Context: mono/mono#17040
Context: mono/mono#17083
Context: mono/mono#17084
Context: mono/mono#17133
Context: mono/mono#17139
Context: mono/mono#17151
Context: mono/mono#17180
Context: mono/mono#17278
Context: mono/mono#17549
Context: mono/mono#17569
Context: mono/mono#17665
Context: mono/mono#17687
Context: mono/mono#17737
Context: mono/mono#17790
Context: mono/mono#17924
Context: mono/mono#17931
Context: https://github.com/mono/mono/issues/26758
Context: https://github.com/mono/mono/issues/37913
Context: xamarin/xamarin-macios#7005
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Dec 3, 2019
Changes: mono/api-snapshot@fc50bc4...45a61d9

        $ git diff --shortstat fc50bc4f...45a61d93
         22 files changed, 775 insertions(+), 474 deletions(-)

Changes: mono/cecil@a6c8f5e...a6a7f5c

        $ git diff --shortstat a6c8f5e1...a6a7f5c0
         55 files changed, 818 insertions(+), 530 deletions(-)

Changes: mono/corefx@1f87de3...49f1c45

        $ git diff --shortstat e4f7102b...49f1c453
         38 files changed, 1171 insertions(+), 419 deletions(-)

Changes: mono/linker@ebe2a1f...e8d054b

        $ git diff --shortstat ebe2a1f4...e8d054bf
         137 files changed, 5360 insertions(+), 1781 deletions(-)

Changes: mono/mono@8946e49...18920a8

        $ git diff --shortstat 8946e49a...18920a83
         1811 files changed, 47240 insertions(+), 48331 deletions(-)

Changes: xamarin/xamarin-android-api-compatibility@a61271e...50a3c52

        $ git diff --shortstat a61271e0...50a3c52d
         1 file changed, 2 insertions(+), 791 deletions(-)

Fixes: #3619

Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1005448
Context: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/967582
Context: dotnet/coreclr#26370
Context: dotnet/coreclr#26479
Context: dotnet/corefx#40455
Context: dotnet/corefx#40578
Context: mono/mono#7377
Context: mono/mono#12421
Context: mono/mono#12586
Context: mono/mono#14080
Context: mono/mono#14725
Context: mono/mono#14772
Context: mono/mono#15261
Context: mono/mono#15262
Context: mono/mono#15263
Context: mono/mono#15307
Context: mono/mono#15308
Context: mono/mono#15310
Context: mono/mono#15646
Context: mono/mono#15687
Context: mono/mono#15805
Context: mono/mono#15992
Context: mono/mono#15994
Context: mono/mono#15999
Context: mono/mono#16032
Context: mono/mono#16034
Context: mono/mono#16046
Context: mono/mono#16192
Context: mono/mono#16308
Context: mono/mono#16310
Context: mono/mono#16369
Context: mono/mono#16380
Context: mono/mono#16381
Context: mono/mono#16395
Context: mono/mono#16411
Context: mono/mono#16415
Context: mono/mono#16486
Context: mono/mono#16570
Context: mono/mono#16605
Context: mono/mono#16616
Context: mono/mono#16689
Context: mono/mono#16701
Context: mono/mono#16712
Context: mono/mono#16742
Context: mono/mono#16759
Context: mono/mono#16803
Context: mono/mono#16808
Context: mono/mono#16824
Context: mono/mono#16876
Context: mono/mono#16879
Context: mono/mono#16918
Context: mono/mono#16943
Context: mono/mono#16950
Context: mono/mono#16974
Context: mono/mono#17004
Context: mono/mono#17017
Context: mono/mono#17038
Context: mono/mono#17040
Context: mono/mono#17083
Context: mono/mono#17084
Context: mono/mono#17133
Context: mono/mono#17139
Context: mono/mono#17151
Context: mono/mono#17180
Context: mono/mono#17278
Context: mono/mono#17549
Context: mono/mono#17569
Context: mono/mono#17665
Context: mono/mono#17687
Context: mono/mono#17737
Context: mono/mono#17790
Context: mono/mono#17924
Context: mono/mono#17931
Context: https://github.com/mono/mono/issues/26758
Context: https://github.com/mono/mono/issues/37913
Context: xamarin/xamarin-macios#7005
ManickaP pushed a commit to ManickaP/runtime that referenced this issue Jan 20, 2020
[android] remove text relocations in AOT/arm32

Remove support for "big assemblies" for AOT on Android running on ARM 32bit. This will remove relocations in `.text` which are not allowed in the upcoming Android Q release anymore.

_If_ a customer should run into this problem, the suggested workarounds are:
* Switch to ARM64, or
* Do not use AOT compilation.

Fixes mono/mono#16369


Commit migrated from mono/mono@b6ca76c
ManickaP pushed a commit to ManickaP/runtime that referenced this issue Jan 20, 2020
…cations (mono/mono#16729)

[aot] move method_addresses to data.rel.so section to avoid text relocations

Another revert of a revert! 🎉 

After some discussions with @grendello and @radekdoulik, we came up with this solution. It's a better attempt to fix mono/mono#16369 as it (1) works within the restrictions of Android 10 and (2) still works for armv7 AOT. 


`.text` relocations aren't allowed in Android 10 (and this change shouldn't hurt on Linux).

AOT compilation:
```console
$ MONO_PATH=/Users/lewurm/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/ \
MONO_ENV_OPTIONS="" \
./sdks/out/android-cross-arm-release/bin/armv7-linux-android-mono-sgen \
--aot=keep-temps,outfile=here.dll.so,asmwriter,mtriple=armv7-linux-gnueabi,tool-prefix=/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-,ld-flags= \
~/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll

Mono Ahead of Time compiler - compiling assembly /Users/lewurm/Downloads/xamarin.android-oss-v10.0.99.136_Darwin-x86_64_pr_766265b9-Debug/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll
AOTID 7DDD05DA-37E0-813A-8C27-3E1634391BB3
Compiled: 144382/144382
Executing the native assembler: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-as"   -mfpu=vfp3 -o /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ.o /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ
Executing the native linker: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld"  -shared -o here.dll.so.tmp  /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ.o
Stripping the binary: "/Users/lewurm/android-toolchain/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip" --strip-symbol=\$a --strip-symbol=\$d here.dll.so.tmp
Retained input file.
JIT time: 15031 ms, Generation time: 7374 ms, Assembly+Link time: 75130 ms.
```

Before:
```console
$ grep -C 6 'method_addresses:' /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_550yHJ
        .align 3
jit_code_end:

        .byte 0,0,0,0
.text 1
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#function
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
$ arm-linux-androideabi-readelf -a here.dll.so | grep -i textrel
 0x00000016 (TEXTREL)                    0x0
 0x0000001e (FLAGS)                      TEXTREL
```

After switching to `.data.rel.so`:
```console
$ grep -C 6 'method_addresses:' /var/folders/p3/5279mmgn1p575bz28j0ngfqw0000gn/T/mono_aot_1YhAgn  # assembly file produced by AOT compiler
jit_code_end:

        .byte 0,0,0,0
.section ".data.rel.ro"
.subsection 0
        .align 3
method_addresses:
        .local method_addresses
        .type method_addresses,#object
ldr pc,=.Lm_0
.ltorg
ldr pc,=.Lm_1
.ltorg
$ arm-linux-androideabi-readelf -a here.dll.so | grep -i textrel
$ echo $?
1
```


Commit migrated from mono/mono@e40e24b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.