Bug 196407 - kernel modules fail on arm after r276047
Summary: kernel modules fail on arm after r276047
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm Any
: --- Affects Many People
Assignee: Ian Lepore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-31 22:43 UTC by Ian Lepore
Modified: 2018-01-04 16:35 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lepore freebsd_committer freebsd_triage 2014-12-31 22:43:36 UTC
r276047 added -march=armv7 to the default arm compile options.  Among other things, this allows the compiler to generate movw/movt sequences to load a constant into a register.  Using those instructions results in relocation types R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS being emitted, and when those types appear in a .ko module they are not being handled correctly by ld.  The lower 16 bits of the relocated value are correct, but the upper 16 bits (used in the movt instruction) are always zero.  This leads to a variety of wild-pointer crashes in the loaded module.

This problem may affect shared libraries in userland too, but we don't currently add the -march=armv7 flag there, it's used only for kernel and module builds now.
Comment 1 commit-hook freebsd_committer freebsd_triage 2015-01-02 03:20:25 UTC
A commit references this bug:

Author: ian
Date: Fri Jan  2 03:20:14 UTC 2015
New revision: 276525
URL: https://svnweb.freebsd.org/changeset/base/276525

Log:
  Put in a workaround for bug 196407 (arm modules cause crashes & panics).

  When we started compiling the kernel with -march=armv7 the compiler
  started emitting new types of relocation info which are incompatible with
  the shared-lib file format used by .ko modules.  This workaround prevents
  the compiler from emitting the instruction sequences that require the
  new relocs.  This amounts to using an undocumented internal compiler
  flag, so this is just a temporary workaround while we look for a good fix.

  PR:		196407

Changes:
  head/sys/conf/kmod.mk
Comment 2 Glen Barber freebsd_committer freebsd_triage 2015-07-07 13:58:00 UTC
Apparently resolved in r276525.

Thank you for your submission.
Comment 3 Ian Lepore freebsd_committer freebsd_triage 2015-12-27 17:31:20 UTC
Re-open.  This problem is not fixed.  There was a temporary workaround added to kernel and module compiles, but there is currently no proper solution and no workaround in place for userland compiles with -march=armv7
Comment 4 Ian Lepore freebsd_committer freebsd_triage 2016-01-02 03:38:59 UTC
Pieces of the fix for this were commited (but I forgot to cite the PR in the commits)...

 r292964 - Fix sign-extension for movw/movt relocs.

 r292870 - When linking, don't generate .plt entries for movw/movt relocs.

 r292993 - Don't generate movw/movt instructions when building libstand since the bootloader self_reloc() code can't handle it (same fix as the original fix for modules).

That leaves one pending issue I know of, which is the need to prevent generation of movt/movw when compiling the rest of ubldr other than libstand.  This is still pending, awaiting input from others.
Comment 5 Ian Lepore freebsd_committer freebsd_triage 2018-01-04 16:35:48 UTC
Some svn archeology shows that the last piece of the fixes for this was committed in r295421, so this can now be closed.