Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#7878 closed defect (wontfix)

x86 builds silently generate text-relocations in the binary.

Reported by: dalecurtis Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Due to this line in x86inc.asm:

%elif ARCH_X86_64 == 0
; x86_32 doesn't require PIC.
; Some distros prefer shared objects to be PIC, but nothing breaks if
; the code contains a few textrels, so we'll skip that complexity.
    %undef PIC
%endif

When linking with lld instead of ld.bfd or gold, you'll end up with errors like this:
ld.lld: error: can't create dynamic relocation R_386_32 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

This is because ld.bfd and gold will silently disable warning about text relocations, from https://crbug.com/911658#c19:

If ld.bfd and gold find text relocations required, they'll silently produce modules with text relocations (DT_TEXTREL or DF_TEXTREL), as if -z notext is specified by the user. lld doesn't have such ondemand semantics - it'll just reject text relocations outright unless -z notext is on the command line.

Removing text relocations improves security and reduces load times:
https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-Enforced-for-API-level-23

So it'd be nice to fix this at some point. Just removing the lines from x86inc.asm will break large swaths of the assembly code unfortunately, so folks with more knowledge of the code will have to take a look.

Change History (3)

comment:1 Changed 7 weeks ago by dalecurtis

Another instance of text relocations are generated if BROKEN_RELOCATIONS=0:

ld.lld: error: can't create dynamic relocation R_386_32 against symbol: ff_h264_cabac_tables in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

These at least can be removed by setting that flag. I note it here for any future reader though.

comment:2 in reply to: ↑ description Changed 7 weeks ago by cehoyos

  • Component changed from build system to undetermined
  • Priority changed from wish to normal
  • Resolution set to wontfix
  • Status changed from new to closed

Replying to dalecurtis:

When linking with lld instead of ld.bfd or gold, you'll end up with errors like this:
ld.lld: error: can't create dynamic relocation R_386_32 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Did you try this?

Removing text relocations improves security and reduces load times:

(Could it be that you mean here "reduces load times at the cost of runtime performance"?)
It was claimed repeatedly on this bug tracker that above is simply not true, I would suggest not to revive this discussion;-)

Last edited 7 weeks ago by cehoyos (previous) (diff)

comment:3 Changed 7 weeks ago by dalecurtis

Yes, we've "fixed" this by adding the flag since we don't really ship any ia32 builds anymore :) I filed this here for tracking any official response and in case any future explorers wonder what's happening.

Note: See TracTickets for help on using tickets.