statically linked executable size

Andrew Haley aph@redhat.com
Mon Jul 3 10:01:00 GMT 2006


Ranjit Mathew writes:
 > -----BEGIN PGP SIGNED MESSAGE-----
 > Hash: SHA1
 > 
 > Marco Trudel wrote:
 > > I noticed that a simple System.out.println() application will have 
 > > different executable sizes when compiling with different gcj versions 
 > > (althought it does exactly the same and needs exactly the same java 
 > > classes):
 > [...]
 > > What is the reason for it? There were already discussions in the list 
 > > about it, but I haven't found an explanation...
 > > Are there more/all classes compiled into the executables as libgcj grows?
 > 
 > One explanation is that more and more methods and classes get
 > implemented in newer GCJ releases, so you should expect to see
 > the executable size increase with newer GCJ releases.
 > 
 > What is particularly worrying to me is that the classes pulled
 > in seem to be increasing quite a bit with newer releases and
 > the visible bloat in statically-compiled executables keeps
 > increasing accordingly. For example, a single "Hello World"
 > executable for MinGW compiles to a 40MB statically-linked
 > executable (15MB when stripped of debugging information) and
 > contains a whopping 28,466 external symbols in the text section!
 > 
 > There are so many classes whose presence in the executable is
 > something that I cannot readily account for - for example, why
 > is javax.swing.JToolBar needed to print "Hello World" on the
 > console?

This one comes up every once in a while, and there's a technique for
finding out.

 $ gcj -static Hello.java --main=Hello -Wl,-Map,Hello.map

Unfortunately I cannot duplicate your problem since my program does
not link javax.swing.*.  I end up with

zebedee:~ $ ls -lh Hello
-rwxr-xr-x 1 aph aph 22M Jul  3 10:50 Hello*
zebedee:~ $ strip Hello
zebedee:~ $ ls -lh Hello
-rwxr-xr-x 1 aph aph 7.1M Jul  3 10:51 Hello*

If you want to find out how you got to javax.swing.JToolBar, look at
the map file.  It'll tell you.

Another thing worth trying is this:

 $ find . -name '*.java' | grep -v swing | xargs grep '^import.*swing'

the results of which are attached.

If you can find the chain of refs that pulls in swing, you can fairly
easily break it.

If you try this, let us know what you discover.

Andrew.


./classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java:import javax.swing.JOptionPane;
./classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java:import javax.swing.JOptionPane;
./classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java:import gnu.javax.swing.text.html.parser.HTML_401F;
./classpath/javax/accessibility/AccessibleEditableText.java:import javax.swing.text.AttributeSet;
./classpath/javax/accessibility/AccessibleAttributeSequence.java:import javax.swing.text.AttributeSet;
./classpath/javax/accessibility/AccessibleText.java:import javax.swing.text.AttributeSet;
./classpath/gnu/xml/dom/html2/DomHTMLParser.java:import gnu.javax.swing.text.html.parser.support.Parser;
./classpath/gnu/xml/dom/html2/DomHTMLParser.java:import javax.swing.text.AttributeSet;
./classpath/gnu/xml/dom/html2/DomHTMLParser.java:import javax.swing.text.html.HTML;
./classpath/gnu/xml/dom/html2/DomHTMLParser.java:import javax.swing.text.html.parser.DTD;
./classpath/gnu/xml/dom/html2/DomHTMLParser.java:import javax.swing.text.html.parser.TagElement;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JButton;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JDialog;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JLabel;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JList;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JPanel;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JPasswordField;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JScrollPane;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JTextArea;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.JTextField;
./classpath/gnu/javax/security/auth/callback/SwingCallbackHandler.java:import javax.swing.ListSelectionModel;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.BorderFactory;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.Box;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.BoxLayout;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.ButtonGroup;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JButton;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JCheckBox;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JComboBox;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JDialog;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JLabel;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JPanel;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JRadioButton;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JSpinner;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JTabbedPane;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.JTextField;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.SpinnerNumberModel;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.border.TitledBorder;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.event.ChangeEvent;
./classpath/gnu/javax/print/PrinterDialog.java:import javax.swing.event.ChangeListener;
./classpath/java/awt/TextComponent.java:import javax.swing.text.AttributeSet;
./classpath/java/awt/event/MouseWheelEvent.java:import javax.swing.JScrollPane;
./classpath/java/awt/event/MouseWheelEvent.java:import javax.swing.Scrollable;
./classpath/java/awt/im/spi/InputMethodContext.java:import javax.swing.JFrame;



More information about the Java mailing list