3 Shared Library Reduction Tool
4 -----------------------------
6 The motivation for this tool was the understanding that the ACE & TAO
7 libraries were to be linked with the VxWorks kernel to allow multiple
8 applications to be run simultaneously with a minimum of footprint
9 consumed. Ordinarily a choice is made between static linking
10 applications, where each application gets only the object modules
11 needed, and shared object linkage, where multiple applications share
12 access to full libraries. Frequently a shared library will contain
13 code and data which is not used by any of the applications in a
14 particular configuration. The Shared Library Reduction Tool builds
15 libraries that include only the modules needed to support a specified
18 The analysis is performed very late in the application implementation,
19 allowing the system implementors the freedom to use whatever TAO & ACE
20 components are needed. Once an application is built and running, its
21 shared object need may be evaluated. The evaluation is straight
22 forward. Run the soreduce program, passing the path to all of the
23 applications that will share the libraries. The soreduce program uses
24 the following steps to generate its results.
26 1. A list of undefined symbols and shared libraries is built by
27 invoking the ldd and nm commands on each application. For now,
28 soreduce assumes the GNU variant of these tools.
30 2. For each shared library, soreduce tries to invoke nm on each of the
31 intermediate object files used to build the library. It is
32 important that target library directory has a current .shobj
35 3. The list of undefined symbols is traversed. For each entry in the list, the
36 modules loaded from step 2 are examined to look for a matching
37 symbol. When one is found, the target symbol, and any others
38 satisfied by the module are removed from the list, and any
39 undefined symbols in the module are added to the list. This
40 process is repeated until the entire list of undefined symbols is
41 traversed without change.
43 4. MPC files are generated. Rather than invoking the linker directly, an mpc
44 file is generated that may be used to build the libs. With these
45 mpc files, the actual library will be named (orig)_subset.
50 Development of the shared library reduction tool also provided a
51 secondary benefit. It is able to output usage metrics for the various
52 modules, which may be useful for directing further hand-crafted
53 reduction efforts. Using the GNU nm with more verbose output, it is
54 possible to determine the first function using a given undefined
55 symbol. While it is not (yet) possible to automate the refactoring of
56 code based on this analysis, this information can provide a road map
57 for breaking a single module into two or a few that will result in
58 fewer incidental dependancies overall. However this speculation has
64 Running soreduce providing itself as the sole client. The soreduce
65 application is built on top of ACE, using just a few of ACE's
66 features. Here is the output:
68 bash$ ./soreduce soreduce
70 loading object modules
71 Libs subject to analysis:
74 pass 0, undef count = 69
75 pass 1, undef count = 207
76 pass 2, undef count = 278
77 pass 3, undef count = 271
78 pass 4, undef count = 245
79 pass 5, undef count = 235
81 Making directory /opt/wustl/ACE_wrappers/build/native/ace/usage_metrics
82 ACE: 61 out of 210 modules required
83 writing file /opt/wustl/ACE_wrappers/build/native/ace/ACE_subset.mpc
86 The size of libACE.so before rebuilding:
89 text data bss dec hex filename
90 2361958 498760 12516 2873234 2bd792 libACE.so
94 bash$ size libACE_subset.so
95 text data bss dec hex filename
96 987167 207452 7580 1202199 125817 libACE_subset.so
99 2873234 - 1202199 = 1671035 bytes eliminated, a 58.2% reduction
101 Here is another example, using the Naming Service, and its simple test
102 client. Note that the orbsvcs results are bogus, the libraries are
103 already fairly well factored so that the additional subsetting by
104 soreduce is not effective. Also, due to the layout of the orbsvcs
105 library source directory, the tool may not generate valid mpc files.
107 bash$ $ACE_ROOT/apps/soreduce/soreduce Naming_Service/Naming_Service tests/Simple_Naming/client
108 discovering libraries
109 loading object modules
110 Libs subject to analysis:
118 pass 0, undef count = 339
119 pass 1, undef count = 580
120 pass 2, undef count = 438
121 pass 3, undef count = 278
122 pass 4, undef count = 244
123 pass 5, undef count = 246
124 pass 6, undef count = 242
126 Making directory /opt/wustl/ACE_wrappers/build/native/TAO/orbsvcs/orbsvcs/usage_metrics
127 TAO_CosNaming: 11 out of 256 modules required
128 writing file /opt/wustl/ACE_wrappers/build/native/TAO/orbsvcs/orbsvcs/TAO_CosNaming_subset.mpc
129 Making directory /opt/wustl/ACE_wrappers/build/native/TAO/orbsvcs/orbsvcs/usage_metrics
130 TAO_Svc_Utils: 8 out of 256 modules required
131 writing file /opt/wustl/ACE_wrappers/build/native/TAO/orbsvcs/orbsvcs/TAO_Svc_Utils_subset.mpc
132 Making directory /opt/wustl/ACE_wrappers/build/native/TAO/tao/IORTable/usage_metrics
133 TAO_IORTable: 4 out of 4 modules required
134 writing file /opt/wustl/ACE_wrappers/build/native/TAO/tao/IORTable/TAO_IORTable_subset.mpc
135 Making directory /opt/wustl/ACE_wrappers/build/native/TAO/tao/PortableServer/usage_metrics
136 TAO_PortableServer: 26 out of 29 modules required
137 writing file /opt/wustl/ACE_wrappers/build/native/TAO/tao/PortableServer/TAO_PortableServer_subset.mpc
138 Making directory /opt/wustl/ACE_wrappers/build/native/TAO/tao/usage_metrics
139 TAO: 160 out of 191 modules required
140 writing file /opt/wustl/ACE_wrappers/build/native/TAO/tao/TAO_subset.mpc
141 Making directory /opt/wustl/ACE_wrappers/build/native/ace/usage_metrics
142 ACE: 75 out of 210 modules required
143 writing file /opt/wustl/ACE_wrappers/build/native/ace/ACE_subset.mpc
147 text data bss dec hex filename
148 2361958 498760 12516 2873234 2bd792 libACE.so
149 3432206 704188 30992 4167386 3f96da libTAO.so
150 1931145 326632 7528 2265305 2290d9 libTAO_PortableServer.so
151 76561 12504 364 89429 15d55 libTAO_IORTable.so
157 text data bss dec hex filename
158 1340017 275440 8140 1623597 18c62d libACE_subset.so
159 3131226 643816 27984 3803026 3a0792 libTAO_subset.so
160 1845515 308812 6896 2161223 20fa47 libTAO_PortableServer_subset.so
161 76603 12508 364 89475 15d83 libTAO_IORTable_subset.so
165 Savings: 1718033 or 18.3%