This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: How can I rewrite _start(entry point) of main function
- From: Siddhesh Poyarekar <siddhesh at gotplt dot org>
- To: Jason Yang <jasonyangshadow at gmail dot com>, libc-alpha at sourceware dot org, libc-help <libc-help at sourceware dot org>
- Date: Sun, 19 Jan 2020 10:01:52 +0530
- Subject: Re: How can I rewrite _start(entry point) of main function
- References: <8a22e151-7038-264f-0c61-555cc0312feb@gmail.com>
(redirecting to libc-help)
On 18/01/20 8:35 pm, Jason Yang wrote:
> Dear developers:
>
> I have a demand that changing the argv array passed to main function
> after execve syscall. I knew that _start or even __libc_start_main are
> called before user's main function is called. Can I use LD_PRELOAD
> tricks to overwrite _start or any other functions in order for the
> modifications of argv before user's main function is called?
>
>
> Thanks so much! Looking forward your responses!
You can use constructors to run code before main() executes. Basically
implement a function with __attribute__((constructor)):
https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html
Siddhesh