From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: 陈金佳 <chenjinjia_cn@163.com>,
"libc-help@sourceware.org" <libc-help@sourceware.org>
Subject: Re: need help about __stack_chk_guard
Date: Wed, 27 Sep 2023 08:59:48 -0300 [thread overview]
Message-ID: <cdcb9566-90bd-49ce-8b96-b4502e10fa03@linaro.org> (raw)
In-Reply-To: <436d1f6d.210bb.18ac9d41133.Coremail.chenjinjia_cn@163.com>
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
prev parent reply other threads:[~2023-09-27 11:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 0:53 陈金佳
2023-09-27 11:59 ` Adhemerval Zanella Netto [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cdcb9566-90bd-49ce-8b96-b4502e10fa03@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=chenjinjia_cn@163.com \
--cc=libc-help@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).