3

I have gone through the linker documentation for HIDDEN and PROVIDE_HIDDEN multiple times, but I am not really able to understand what they exactly do.

For example, if I write a linker script with an assignment like this :

naveen = 10;
SECTIONS
  {

  }

I see the symbol in

$ objdump -t kernel8.elf  | grep naveen
000000000000000a g       *ABS*  0000000000000000 naveen

If I add HIDDEN, I still see the symbol there :

HIDDEN(naveen = 10);
SECTIONS
  {
  }

$ objdump -t kernel8.elf  | grep naveen
000000000000000a l       *ABS*  0000000000000000 naveen

For PROVIDE and PROVIDE_HIDDEN added in SECTIONS command, I don't see the symbol in either case. So I am not really able to differentiate between HIDDEN/non-hidden and PROVIDE/PROVIDE_HIDDEN behaviours. Can someone please explain with nice and short example the use-cases. I searched a lot but either I did not find good examples, or I could not make sense out of it.

old_timer
  • 69,149
  • 8
  • 89
  • 168
Naveen
  • 7,944
  • 12
  • 78
  • 165
  • 1
    Notice the flag changed from `g` to `l`. As for `PROVIDE` the manual says _"The PROVIDE keyword may be used to define a symbol, such as ‘etext’, only if it is referenced but not defined. "_. So you will only see it if you reference it somewhere. – Jester Jan 26 '22 at 12:52
  • 1
    Oh I missed that. So the documentation also said that in case of `HIDDEN`, none of the symbols will be visible outside the current module. So what's `module` here ? Is the module referring to the current output file/executable being linked? Then it makes sense. – Naveen Jan 26 '22 at 14:21
  • 1
    The current file, yes. – Jester Jan 26 '22 at 14:33
  • 1
    I may be missing something but I still don't understand the behaviour of PROVIDE_HIDDEN... – Axel B Mar 04 '22 at 10:53

0 Answers0