Bug 23078 - Weak alias to a weak symbol is not resolved correctly.
Summary: Weak alias to a weak symbol is not resolved correctly.
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-18 13:29 UTC by Vadzim Dambrouski
Modified: 2018-10-18 07:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Archive with code to reproduce this issue. (499 bytes, application/gzip)
2018-04-18 13:29 UTC, Vadzim Dambrouski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vadzim Dambrouski 2018-04-18 13:29:07 UTC
Created attachment 10957 [details]
Archive with code to reproduce this issue.

Example code

// main.c -------------------

void _start() {}

void DEFAULT_HANDLER() {
  *((int*)0x10) = 5;
}

// foo.c --------------------

__attribute__((weak)) void DEFAULT_HANDLER() {
    *((int*)0x10) = 1;
}

__attribute__((weak, alias("DEFAULT_HANDLER"))) void HARD_FAULT();
__attribute__((weak, alias("DEFAULT_HANDLER"))) void BUS_FAULT();

void (*VECTORS[])() = {
    HARD_FAULT,
    BUS_FAULT,
};

// compile with ---------------

gcc -Os -o main.o -c main.c
gcc -Os -o foo.o -c foo.c
ld main.o foo.o
objdump -d -j .text -j .data a.out > dump.txt

// ----------------

VECTORS array points to a weak function instead of a strong function defined in main.c
Comment 1 Nick Clifton 2018-05-17 16:05:01 UTC
Hi Vadzim,

> VECTORS array points to a weak function instead of a strong function defined
> in main.c

I think that this is a bug in your test code.  You should be using the
weakref attribute here, rather than the weak and alias attributes.  IE:

  static __attribute__((weakref ("DEFAULT_HANDLER"))) void HARD_FAULT ();

and similarly for BUS_FAULT.

Cheers
  Nick
Comment 2 Vadzim Dambrouski 2018-07-19 09:37:05 UTC
Hello Nick,

Thank you for suggestion, I've tried weakref, and does help with the case I have posted above, but it still doesn't do exactly what I need.

Here is updated code:

// main.c -------------------

void _start() {}

void DEFAULT_HANDLER() {
  *((int*)0x10) = 5;
}

void BUS_FAULT() {
  *((int*)0x10) = 7;
}

// foo.c --------------------

__attribute__((weak)) void DEFAULT_HANDLER() {
    *((int*)0x10) = 1;
}

static __attribute__((weakref ("DEFAULT_HANDLER"))) void HARD_FAULT();
static __attribute__((weakref ("DEFAULT_HANDLER"))) void BUS_FAULT();

void (*VECTORS[])() = {
    HARD_FAULT,
    BUS_FAULT,
};

// ----------------------

In this new example I have created a strong symbols for both default handler and for one of specific handlers. I expect that VECTORS table would contain pointers to functions 5 and 7, but in practice it contains pointers to 5 and 5. This is not what I need, unfortunately.

Regards,
Vadzim
Comment 3 Alan Modra 2018-10-18 07:49:09 UTC
Not a linker bug, and original reporter has probably figured out what is wrong with his code by now.  In an case, asking binutils developers how to use gcc features via a bug report is not appropriate.