Best practices for libraries and linkers (part 8)

Part 8 is the conclusion of the series on the best practices for libraries and linking. The core set of best practices are:

  • Ensure at link time that all symbols are resolved.
  • Minimise the number of symbols of global scope.
  • Specify the library search paths at link time.

Putting this series of articles together turned out to be a fair amount of work. Hopefully you can see from the scale of the topics why we chose to break it down into bite-sized chunks. I'll be happy to hear feedback on whether you found it useful, or what other topics you would like discussed.

Comments:

About $ORIGIN, it is very unfortunate that the symbol used is "string" ("$"). Why was this symbol chosen, do you know?

Be that as it might, here is the trick I use:

setenv ORIGIN '$ORIGIN'
setenv O '$$O'

Since no shell will expand $ORIGIN recursively, when it is expanded it will always be "$ORIGIN". The "$$O" construct is for make(1S). When make(1S) sees "$ORIGIN" referenced, it will attempt to expand the $O macro, and since the $O macro is set to "$$O", it will be expanded to "$O", so make(1S) will end up with "$ORIGIN" after the expansion. If this is ever passed to a shell at any point, the setenv ORIGIN '$ORIGIN' will expand it to "$ORIGIN" again.

Posted by guest on July 15, 2011 at 04:34 AM PDT #

Best practice -R:

32-bit:
-R'$ORIGIN:$ORIGIN/../lib:$ORIGIN/../../lib:/opt/company/lib'

64-bit:
-R'$ORIGIN:$ORIGIN/../lib/64:$ORIGIN/../../lib/64:/opt/company/lib/64'

...with the caveat that $ORIGIN does not work for SUID binaries.

Posted by UX-admin on July 15, 2011 at 04:41 AM PDT #

Thanks for the suggestions! No idea why $ORIGIN was chosen - I agree that it's awkward.

Darryl.

Posted by Darryl Gove on July 15, 2011 at 06:04 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

Darryl Gove is a senior engineer in the Solaris Studio team, working on optimising applications and benchmarks for current and future processors. He is also the author of the books:
Multicore Application Programming
Solaris Application Programming
The Developer's Edge

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
5
6
8
9
10
12
13
14
15
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks
The Developer's Edge
Solaris Application Programming
Publications
Webcasts
Presentations
OpenSPARC Book
Multicore Application Programming
Docs