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

Support 16kb page size in gomobile builds #300

Open
marcin-michalek-miquido opened this issue Sep 24, 2024 · 3 comments
Open

Support 16kb page size in gomobile builds #300

marcin-michalek-miquido opened this issue Sep 24, 2024 · 3 comments

Comments

@marcin-michalek-miquido

Hello,

since recently it's possible to compile for 16kb memory page size Android devices.
I am building gopenpgp for Android using the build.sh and I am trying to figure out how to modify it according to Google tips here: https://source.android.com/docs/core/architecture/16kb-page-size/16kb#build-lib-16kb-alignment

I tried modyfing

./gomobile bind -tags $TAGS -target $TARGET $JAVAPKG_FLAG -x -ldflags="-s -w " -o ${TARGET_OUT_FILE}  ${PACKAGES}

in the build.sh by adding flags

-ldflags="-s -w -Wl -z max-page-size=16384"

but got: flag provided but not defined: -Wl error when building.

I suspect it may be because I use older NDK (23) and the linker does not know the flags, but when trying with the latest (27) I have:

./gomobile: no usable NDK: unsupported API version 16 (not in 21..35)

not sure what else to try. Can you help?
This applies to both v2 and v3 lirabry.

@250king
Copy link

250king commented Nov 21, 2024

I have the same issue, too. I have use the latest version of NDK and build. But when I run it in 16kb-system, it is crashed.
image

@250king
Copy link

250king commented Nov 27, 2024

Now I am understand how to build the 16kb paging library. if you run go env, you can find

...
CGO_LDFLAGS='-O2 -g'
...

Then try to set the variable and build without any ldflag in gomobile

export CGO_LDFLAGS="-O2 -g -s -w -Wl,-z,max-page-size=16384"
gomobile bind -v -androidapi 21 .

You can get the 16kb paging library. Use readelf you can find the Align is 0x4000

$ readelf -l *


Elf 文件类型为 DYN (共享目标文件)
Entry point 0x0
There are 10 program headers, starting at offset 64

程序头:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
                 0x0000000000000230 0x0000000000000230  R      0x8
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000004d7488 0x00000000004d7488  R      0x4000
  LOAD           0x00000000004d7490 0x00000000004db490 0x00000000004db490
                 0x0000000000ac9930 0x0000000000ac9930  R E    0x4000
  LOAD           0x0000000000fa0dc0 0x0000000000fa8dc0 0x0000000000fa8dc0
                 0x0000000000b5f4d8 0x0000000000b60240  RW     0x4000
  LOAD           0x0000000001b002a0 0x0000000001b0c2a0 0x0000000001b0c2a0
                 0x00000000000b7598 0x00000000000fa750  RW     0x4000
  DYNAMIC        0x0000000001affd90 0x0000000001b07d90 0x0000000001b07d90
                 0x00000000000001b0 0x00000000000001b0  RW     0x8
  GNU_RELRO      0x0000000000fa0dc0 0x0000000000fa8dc0 0x0000000000fa8dc0
                 0x0000000000b5f4d8 0x0000000000b60240  R      0x1
  GNU_EH_FRAME   0x00000000004d5368 0x00000000004d5368 0x00000000004d5368
                 0x000000000000053c 0x000000000000053c  R      0x4
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x0
  NOTE           0x0000000000000270 0x0000000000000270 0x0000000000000270
                 0x00000000000000fc 0x00000000000000fc  R      0x4

 Section to Segment mapping:
  段节...
   00     
   01     .note.android.ident .note.go.buildid .dynsym .gnu.version .gnu.version_r .gnu.hash .dynstr .rela.dyn .rela.plt .rodata .eh_frame_hdr .eh_frame 
   02     .text .plt 
   03     .data.rel.ro .fini_array .init_array .dynamic .got .got.plt .relro_padding 
   04     .go.buildinfo .noptrdata .data .bss .noptrbss 
   05     .dynamic 
   06     .data.rel.ro .fini_array .init_array .dynamic .got .got.plt .relro_padding 
   07     .eh_frame_hdr 
   08     
   09     .note.android.ident .note.go.buildid

@marcin-michalek-miquido
Copy link
Author

@250king That worked, thanks for posting! I did the check with Google script and it also confirms the correct alignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants