public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ld: Symbol type of a symbol assignment?
@ 2020-08-03 23:41 Fangrui Song
  2020-08-18  5:53 ` Fangrui Song
  0 siblings, 1 reply; 2+ messages in thread
From: Fangrui Song @ 2020-08-03 23:41 UTC (permalink / raw)
  To: binutils

cat > a.s <<e
  .type fun,@function
  .type ifunc,@gnu_indirect_function
  .type obj,@object
  .globl _start, fun, ifunc, obj
  _start: fun: ifunc: obj: ret
e
as a.s -o a.o
ld.bfd a.o --defsym 'bar=ifunc+1' => bar is STT_GNU_IFUNC

Let's try some other expressions:
* --defsym 'bar=ifunc+ifunc' => bar is STT_NOTYPE. The sum is not
   meaningful, so downgrading to STT_NOTYPE seems fine.

The forms '--defsym' supports are limited. So I'll switch to -T for
other symbol assignments.

* -T =(printf 'bar = obj - obj;') => bar is STT_NOTYPE.
* -T =(printf 'bar = obj / 2;') => bar is STT_OBJECT.
   Division does not create a meaningful symbol reference, so I expected STT_NOTYPE.
   I don't get upset by STT_OBJECT, though.
* -T =(printf 'bar = obj * 2;') => similarly, bar is STT_OBJECT.
* -T =(printf 'bar = !obj;') => bar is STT_OBJECT.
* -T =(printf 'bar = ~obj;') => bar is STT_OBJECT.
* -T =(printf 'bar = -obj;') => bar is STT_OBJECT.
* ...

So what are rules for the symbol type? For direct aliases like `bar = ifunc`,
I think having the same type as the aliased symbol is fine. This is even
desired because in some backends, symbol types can affect relocation processing
(for example, if the referenced symbol is not STT_FUNC, no interworking is performed)

For `ifunc+1`, I am less sure that retaining the original type is reasonable:
how can you tell there is another entity of the same type at the plus 1 address ?

For other expressions, I am even less sure that retaining the original type is reasonable.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: ld: Symbol type of a symbol assignment?
  2020-08-03 23:41 ld: Symbol type of a symbol assignment? Fangrui Song
@ 2020-08-18  5:53 ` Fangrui Song
  0 siblings, 0 replies; 2+ messages in thread
From: Fangrui Song @ 2020-08-18  5:53 UTC (permalink / raw)
  To: binutils

Comments? :)

On 2020-08-03, Fangrui Song wrote:
>cat > a.s <<e
> .type fun,@function
> .type ifunc,@gnu_indirect_function
> .type obj,@object
> .globl _start, fun, ifunc, obj
> _start: fun: ifunc: obj: ret
>e
>as a.s -o a.o
>ld.bfd a.o --defsym 'bar=ifunc+1' => bar is STT_GNU_IFUNC
>
>Let's try some other expressions:
>* --defsym 'bar=ifunc+ifunc' => bar is STT_NOTYPE. The sum is not
>  meaningful, so downgrading to STT_NOTYPE seems fine.
>
>The forms '--defsym' supports are limited. So I'll switch to -T for
>other symbol assignments.
>
>* -T =(printf 'bar = obj - obj;') => bar is STT_NOTYPE.
>* -T =(printf 'bar = obj / 2;') => bar is STT_OBJECT.
>  Division does not create a meaningful symbol reference, so I expected STT_NOTYPE.
>  I don't get upset by STT_OBJECT, though.
>* -T =(printf 'bar = obj * 2;') => similarly, bar is STT_OBJECT.
>* -T =(printf 'bar = !obj;') => bar is STT_OBJECT.
>* -T =(printf 'bar = ~obj;') => bar is STT_OBJECT.
>* -T =(printf 'bar = -obj;') => bar is STT_OBJECT.
>* ...
>
>So what are rules for the symbol type? For direct aliases like `bar = ifunc`,
>I think having the same type as the aliased symbol is fine. This is even
>desired because in some backends, symbol types can affect relocation processing
>(for example, if the referenced symbol is not STT_FUNC, no interworking is performed)
>
>For `ifunc+1`, I am less sure that retaining the original type is reasonable:
>how can you tell there is another entity of the same type at the plus 1 address ?
>
>For other expressions, I am even less sure that retaining the original type is reasonable.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-18  5:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03 23:41 ld: Symbol type of a symbol assignment? Fangrui Song
2020-08-18  5:53 ` Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).