* need help about __stack_chk_guard
@ 2023-09-25 0:53 陈金佳
2023-09-27 11:59 ` Adhemerval Zanella Netto
0 siblings, 1 reply; 2+ messages in thread
From: 陈金佳 @ 2023-09-25 0:53 UTC (permalink / raw)
To: libc-help
[-- Attachment #1: Type: text/plain, Size: 913 bytes --]
hello, i am a developer from china and i have encountered a tricky problem in the current development process.
I need to compile a dynamic library, but i don't want to use symbols with "@GLIBC in the dynamic library, because it needs to be used in different glibc runtime environments. Therefore, during the compilation and linking process, I used the -Wl,--wrap compilation option to change the glibc symbols used to __wrap_xxxx. However, this method only works for functions. Because i must use "-fstack-protector-strong",the compiled dynamic library will add "__stack_chk_guard" symbol, which is an OBJECT and cannot be replaced. I hope to get some help from you.
1. Is there a way to replace "__stack_chk_guard" or remove "@GLIBC_2.4" from "__stack_chk_guard@GLIBC_2.4"?
2.If there is no way to replace it, is "__stack_chk_guard" only avaliable in the GLIBC2.4 version within visible time?
thank you!
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: need help about __stack_chk_guard
2023-09-25 0:53 need help about __stack_chk_guard 陈金佳
@ 2023-09-27 11:59 ` Adhemerval Zanella Netto
0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2023-09-27 11:59 UTC (permalink / raw)
To: 陈金佳, libc-help
On 24/09/23 21:53, 陈金佳 via Libc-help wrote:
> hello, i am a developer from china and i have encountered a tricky problem in the current development process.
> I need to compile a dynamic library, but i don't want to use symbols with "@GLIBC in the dynamic library, because it needs to be used in different glibc runtime environments. Therefore, during the compilation and linking process, I used the -Wl,--wrap compilation option to change the glibc symbols used to __wrap_xxxx. However, this method only works for functions. Because i must use "-fstack-protector-strong",the compiled dynamic library will add "__stack_chk_guard" symbol, which is an OBJECT and cannot be replaced. I hope to get some help from you.
> 1. Is there a way to replace "__stack_chk_guard" or remove "@GLIBC_2.4" from "__stack_chk_guard@GLIBC_2.4"?
> 2.If there is no way to replace it, is "__stack_chk_guard" only avaliable in the GLIBC2.4 version within visible time?
>
> thank you!
Afaik --wrap ld option works for any symbol:
$ cat > lib.c <<EOF
int foo = 42;
EOF
$ cat > version.script <<EOF
VERS_1.1 {
global:
foo;
};
EOF
$ gcc -Wall -fPIC -shared -o lib.so -Wl,--version-script=version.script lib.c
$ readelf -s lib.so | grep -w foo | head -n 1
6: 0000000000004020 4 OBJECT GLOBAL DEFAULT 20 foo@@VERS_1.1
$ cat > main.c <<EOF
#include <stdio.h>
extern int foo;
int __wrap_foo = 24;
int main (int argc, char *argv[])
{
printf ("foo=%d\n", foo);
}
EOF
$ gcc -Wall main.c -o main -Wl,-rpath,`pwd` lib.so && ./main
foo=42
$ gcc -Wall main.c -o main -Wl,-rpath,`pwd` lib.so -Wl,--wrap=foo && ./main
foo=24
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-27 11:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25 0:53 need help about __stack_chk_guard 陈金佳
2023-09-27 11:59 ` Adhemerval Zanella Netto
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).