![]() |
| | #1 |
| Registered User Join Date: Jun 2008
Posts: 19
| gcc: Speify address for a function while compiling I am working on security topics, and I need to write a C file that has only one function in it (without the main routine). I need to compile it. Normally the compilation commands for it would be gcc -c blank.c -o blank.o This crates a .o file starting at address 0 with just the single routine inside the .o file. My question is whether I can make the routine be given a specific address, say for example 8048000 instead of starting at location 0. Thanks in advance. |
| raghu2383 is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| You can do that by setting the right parameters for "ld" when you link it to form an executable. gcc doesn't have any clue about absolute addresses in the code. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 | |
| The wheel reinvent0^r Join Date: Aug 2008 Location: Србија
Posts: 115
| It's -e func specifically.
__________________ I reinvent the wheel to understand how it works. Platform: Windows XP SP2 Professional Edition Compiler: GCC 4.3.0 Editor: Notepad++ 5.4.2 Notes: Successfully using MSYS, loving my Windows makefiles. Never, ever use Cygwin. --Quotes-- Quote:
| |
| hauzer is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| That tells the linker you want to start in func, but not what the original post asked for, which is that the code should be located at a particular address. Edit: To locate the code at a specific address, "ld -Ttext org ... " is the command to use, where org is the origin. I'm not sure if you can actually specify this to any byte address - I'm pretty sure that the OS loads a page at a time, so even if it's a precise address, "funny things" may happen with an address that is not precisely on a 4KB boundary. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. Last edited by matsp; 11-18-2008 at 08:00 AM. |
| matsp is offline | |
| | #5 |
| Registered User Join Date: Jan 2008 Location: Seattle
Posts: 476
| 8048000 is the start of most Linux distros for the stack. I would not hard compile that either as that would not be portable. You can also see this within your /proc dirctory as well during alive session of the program or within gdb for stack analysis. Funny that the book 'Self-Service Linux' talks about this a bit. |
| slingerland3g is offline | |
| | #6 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
| | #7 |
| Registered User Join Date: Jan 2008 Location: Seattle
Posts: 476
| For local variables that is correct. The 0804 addressess range would be the code segment. |
| slingerland3g is offline | |
| | #8 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
| | #9 | ||
| The wheel reinvent0^r Join Date: Aug 2008 Location: Србија
Posts: 115
| Quote:
__________________ I reinvent the wheel to understand how it works. Platform: Windows XP SP2 Professional Edition Compiler: GCC 4.3.0 Editor: Notepad++ 5.4.2 Notes: Successfully using MSYS, loving my Windows makefiles. Never, ever use Cygwin. --Quotes-- Quote:
| ||
| hauzer is offline | |
| | #10 | |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| Quote:
| |
| itCbitC is offline | |
| | #11 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
![]() |
| Tags |
| gcc, position dependent code |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Seg Fault in Compare Function | tytelizgal | C Programming | 1 | 10-25-2008 03:06 PM |
| In over my head | Shelnutt2 | C Programming | 1 | 07-08-2008 06:54 PM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| Compiling Errors - return makes integer..., function returns address... | cproghelp | C Programming | 2 | 12-07-2004 02:31 AM |
| qt help | Unregistered | Linux Programming | 1 | 04-20-2002 09:51 AM |