Currently, when I create a shared library, functions from within the same object files like to lie together. Is there a good solution (that does not involve splitting up source files) to try and spread function locations apart? We are currently using a cross-compiled, 4.2.1 version of gcc and the gnu tools.
Asked
Active
Viewed 150 times
1
-
As horrible as it sounds, security. Licensing issues, etc. I'd rather not clue an attacker in that functions A, B, and C which are right next to each other are all related. I know, it's a terrible reason, and it won't really do a lot, but even a little bit can help. – vol Aug 13 '09 at 22:26
1 Answers
0
While you can do what you want using GNU-ld linker script (if you are on platform for which GNU ld works), you can't do it portably.
In addition, it's a totally wasted effort: any hacker worth their salt will not care about moving functions around. If you really want to make it harder to reverse engineer your code (or just bypass your license scheme), you should use much stronger techniques, described e.g. here.
Arguably, that's still totally wasted effort.

Employed Russian
- 199,314
- 34
- 295
- 362
-
Thanks. I understand the arguments that fighting crackers is a losing battle. That said, some of the push for this is management driven, not developer driven. – vol Aug 17 '09 at 12:53
-
Can you do it without putting entries in the linker script for every function? C++ has a lot of generated functions from template instantiations making that impractical for even small code bases. I have non-crack/hack proofing reason for wanting to randomize function locations. – Joseph Garvin Feb 12 '20 at 21:18
-
1@JosephGarvin I don't see why C vs C++ matters: there are likely too many functions to assign manually either way. So you run a normal link, then `nm a.out` to find all the relevant functions, then `sort -R` to randomize their order and generate a linker script, and finally a second link using the generated linker script, to produce randomized binary. – Employed Russian Feb 12 '20 at 22:12
-
@EmployedRussian oh, can I take an existing binary and run the linker script on it and have it rearrange it, or do you mean I do a new fresh link? – Joseph Garvin Feb 12 '20 at 22:36
-
@JosephGarvin I mean a fresh new link, using the same compiled object files. You could also skip the first link if you know all the objects selected into the link (but this is rare). – Employed Russian Feb 13 '20 at 04:05