What does libc_hidden_proto in the glibc standard libraries do?
Asked Answered
C

2

6

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.

Centesimo answered 18/5, 2016 at 4:18 Comment(2)
What version of glibc are you using? I don't have libc_hidden_proto anywhere, but I do remember it from old times ...Aerostatics
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.Centesimo
A
6

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)
Aerostatics answered 18/5, 2016 at 7:33 Comment(2)
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 :PCentesimo
@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.Aerostatics
N
0

Duplicate question libc_hidden_proto macro in gnu library C

Seems to be handeling the namespace.

Originally I thought it had something to do with strict aliasing si ce I found it on malloc and free but I have no other basis for that

Nibelungenlied answered 21/4 at 14:34 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewStillas

© 2022 - 2024 — McMap. All rights reserved.