Last Comment Bug 723939 - Linker needs to align to 16k boundaries on armv6
: Linker needs to align to 16k boundaries on armv6
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: mozglue (show other bugs)
: unspecified
: ARM Android
: -- normal with 1 vote (vote)
: mozilla13
Assigned To: Mike Hommey [:glandium]
:
Mentors:
Depends on: 725284
Blocks: 697205
  Show dependency treegraph
 
Reported: 2012-02-03 07:38 PST by Ted Mielczarek [:ted.mielczarek]
Modified: 2012-03-08 14:25 PST (History)
9 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
When reserving memory for the loaded library, ensure correct alignment for future MAP_SHARED mappings (1.58 KB, patch)
2012-02-08 02:16 PST, Mike Hommey [:glandium]
taras.mozilla: review+
Details | Diff | Review
When reserving memory for the loaded library, ensure correct alignment for future MAP_SHARED mappings (1.91 KB, patch)
2012-02-15 06:30 PST, Mike Hommey [:glandium]
taras.mozilla: review+
Details | Diff | Review
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7 (1.38 KB, patch)
2012-02-15 07:35 PST, Mike Hommey [:glandium]
no flags Details | Diff | Review
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7 (1.38 KB, patch)
2012-02-16 00:30 PST, Mike Hommey [:glandium]
no flags Details | Diff | Review
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7 (1.41 KB, patch)
2012-02-16 09:54 PST, Mike Hommey [:glandium]
ted: review+
Details | Diff | Review

Description Ted Mielczarek [:ted.mielczarek] 2012-02-03 07:38:05 PST
After some detective work by glandium, sewardj, and jbramley, we found out that the reason the linker is failing on my armv6 builds is because there's a 16k alignment requirement.
Comment 1 Mike Hommey [:glandium] 2012-02-08 02:16:16 PST
Created attachment 595355 [details] [diff] [review]
When reserving memory for the loaded library, ensure correct alignment for future MAP_SHARED mappings
Comment 2 Mike Hommey [:glandium] 2012-02-08 02:22:24 PST
As mentioned on IRC, another part of the problem is that the static linker doesn't help either, and we want it to align segments at 16k boundaries (that is, we need (p_vaddr - p_offset) % 16384 == 0).
This can be done with -Wl,-z,max-page-size=0x4000 in LDFLAGS. I'm not completely sure which of configure.in or mozconfig this should live in.
Comment 3 Ted Mielczarek [:ted.mielczarek] 2012-02-08 04:59:05 PST
I think we should automatically add that to LDFLAGS in configure if we're targeting Android-armv6.
Comment 4 Mike Hommey [:glandium] 2012-02-08 05:02:55 PST
armv6 or less, since armv5 code can run on armv6.
Comment 5 (dormant account) 2012-02-08 14:49:59 PST
Comment on attachment 595355 [details] [diff] [review]
When reserving memory for the loaded library, ensure correct alignment for future MAP_SHARED mappings

seems harmless
Comment 6 Mike Hommey [:glandium] 2012-02-15 06:18:49 PST
Mmmmm interestingly, this breaks the linker on desktop :-/
Comment 7 Mike Hommey [:glandium] 2012-02-15 06:30:32 PST
Created attachment 597384 [details] [diff] [review]
When reserving memory for the loaded library, ensure correct alignment for future MAP_SHARED mappings

I'm not entirely sure why it was breaking desktop and not android, but there seems to be pretty bad side effects keeping the mapping MAP_SHARED. So once we get a base address that can hold the library and that will work with MAP_SHARED later, just remap it MAP_PRIVATE instead.
Comment 8 Mike Hommey [:glandium] 2012-02-15 07:35:22 PST
Created attachment 597402 [details] [diff] [review]
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7
Comment 9 Mike Hommey [:glandium] 2012-02-16 00:30:59 PST
Created attachment 597711 [details] [diff] [review]
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7

There were single quotes instead of double quotes in the previous patch
Comment 10 Mike Hommey [:glandium] 2012-02-16 09:54:43 PST
Created attachment 597872 [details] [diff] [review]
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7

This applies the flag to nspr, too.
Comment 11 Ted Mielczarek [:ted.mielczarek] 2012-02-16 12:50:04 PST
Comment on attachment 597872 [details] [diff] [review]
part 2 - Ensure 16k alignment of ELF segments when building for ARM < v7

Review of attachment 597872 [details] [diff] [review]:
-----------------------------------------------------------------

::: configure.in
@@ +4091,5 @@
> +dnl Using the custom linker on ARMv6 requires 16k alignment of ELF segments.
> +if test -n "$MOZ_LINKER"; then
> +  if test "$CPU_ARCH" = arm; then
> +    dnl Determine the target ARM architecture (5 for ARMv5, v5T, v5E, etc.; 6 for ARMv6, v6K, etc.)
> +    ARM_ARCH=`${CC-cc} ${CFLAGS} -dM -E - < /dev/null | sed -n 's/.*__ARM_ARCH_\([[0-9]]*\).*/\1/p'`

Kind of awkward, but I don't have a better suggestion.

@@ +4095,5 @@
> +    ARM_ARCH=`${CC-cc} ${CFLAGS} -dM -E - < /dev/null | sed -n 's/.*__ARM_ARCH_\([[0-9]]*\).*/\1/p'`
> +    dnl When building for < ARMv7, we need to ensure 16k alignment of ELF segments
> +    if test -n "$ARM_ARCH" && test "$ARM_ARCH" -lt 7; then
> +      LDFLAGS="$LDFLAGS -Wl,-z,max-page-size=0x4000"
> +      _SUBDIR_LDFLAGS="$LDFLAGS"

Do we really want to stick all of our LDFLAGS in SUBDIR_LDFLAGS, or just this one thing?

Note You need to log in before you can comment on or make changes to this bug.