Bug 4638 - Discarded Sections with references don't cause errors (ARM/Thumb interworking)
Summary: Discarded Sections with references don't cause errors (ARM/Thumb interworking)
Status: RESOLVED WONTFIX
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-13 18:37 UTC by Axel Heider
Modified: 2022-08-25 04:29 UTC (History)
1 user (show)

See Also:
Host: i386/cygwin
Target: ARM
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Heider 2007-06-13 18:37:30 UTC
I have a script like this to create and ELF file for a ARM CPU.

SECTIONS {
  .text 0x00100000 : {
    . = ALIGN(64);
    *(.text)
  } :text
  .data 0x00200000 : AT(ADDR(.text) + SIZEOF(.text)) {
    . = ALIGN(4);
    *(.data)
  } :data
  .bss : AT(LOADADDR(.data) + SIZEOF(.data)) {
    . = ALIGN(4);
    *(.bss)
  } :data
  
  /DISCARD/ : {
    *(*)
  }
}

This worked fine until I started using code that required ARM/Thumb
interworking. Then the app crashed. The disassembly showw that calls to the
functions requiring interworking look like this:

Address   opcode        mnemonic     comment
...
1299a8:	  ebfb5994 	bl 0         ;call foo1()
...
1299e4:   ebfb5988 	bl c         ;call foo2()
...
129a24:   ebfb597b 	bl 18        ;call foo3()
...

So I have an elf file, with wired jumps (like "bl 0") instead of the correct
interworking function calls. I found out that the interworking feature creates
two new "magic" sections called .glue_7 and .glue_7t. Unfortunately, the
"/DISCARD/" block in my linker script removes them. So the quick solution is to
add *(.glue_7) and *(.glue_7t) to my linker script. 
I admint, that it is my fault that the stub code from .glue_7/.glue_7t is
missing. But I would still expect an error to be thrown here. When I look at the
interworking stubs from .glue_7/.glue_7t I find this symbols.

0013f670 __foo1_from_arm
0013f67c __foo2_from_arm
0013f688 __foo3_from_arm

So, what seem to happen is this. If you look at the "bl x" above and the
addresses of the stubs, it seem that ld still puts the relative offsets right.
It's just the offset of the  discarded sections .glue_7/.glue_7t that is set to
zero or not added at all. 

Why doesn't ld throw an error here, that .glue_7/.glue_7t simply cannot be
discarded, because the code will no longer work correctly?
Comment 1 Alan Modra 2022-08-25 00:17:35 UTC
Yes, things don't work if you write bad linker scripts.
Comment 2 Axel Heider 2022-08-25 01:37:45 UTC
Well, you have a point there - but don't you think emitting at least a warning here makes sense as this is a corner case one can run into by accident? Emitting non-working code seems not really useful either. I doubt there is a use case where one wants this NULL jumps. So why not catch this usage error?
Comment 3 Alan Modra 2022-08-25 04:29:52 UTC
Sorry, we have just too many bugzilla entries to handle.  It's like this.  Everyone who has looked at this bugzilla entry has decided "No, I won't fix this one today".  You also have decided, "It's not worth me spending the time to learn how to fix this myself."  For 15 years!  Thus everyone has voted WONTFIX, regardless of how nice the feature might be.