4

I was trying to look up the prototype for the getpgrp() function in unistd.h but couldnt find it. The only line containing getpgrp in that file was the line libc_hidden_proto (tcgetpgrp) and I'm assuming this is a macro, but I dont know what it does.

I googled but couldn't find any explanations on the web for what libc_hidden_proto actually does. Any explanation about what the purpose of that macro is in glibc would be appreciated.

DarkCygnus
  • 5,985
  • 3
  • 33
  • 52
Jerry Marbas
  • 165
  • 7
  • What version of glibc are you using? I don't have `libc_hidden_proto` anywhere, but I do remember it from old times ... – o11c May 18 '16 at 04:38
  • Thats strange. I'm using glibc 2.19 but Im also looking at the unistd.h header file in glibc 2.18, 2.20, 2.21, and 2.23 and I see libc_hidden_proto in all those versions. – Jerry Marbas May 18 '16 at 05:20

1 Answers1

5

You've accidentally looked at the internal copy (include/unistd.h) instead of the public copy (posix/unistd.h). No, I don't understand how glibc's source is organized either.

From include/libc-symbols.h:

   The following macros are used for PLT bypassing within libc.so
   (and if needed other libraries similarly).
   First of all, you need to have the function prototyped somewhere,
   say in foo/foo.h:
   int foo (int __bar);
   If calls to foo within libc.so should always go to foo defined in libc.so,
   then in include/foo.h you add:
   libc_hidden_proto (foo)
o11c
  • 13,564
  • 4
  • 46
  • 66
  • Thanks. I've actually already read what it says in libc-symbols.h but I didnt understand what a PLT was and so I didnt mention libc-symbols in my question. But +1 for your answer anyways. Now I'm off to read about the PLT, GOT, ELF files, linkers, dynamic loading and the rest of the other million other things I dont know about :P – Jerry Marbas May 19 '16 at 01:32
  • @jerry basically, it's like `-fsemantic-interposition` for just those symbols. And it only works within glibc due to all the other crazy stuff they do. – o11c May 19 '16 at 06:24