statically linked executable size

Andrew Haley
Mon Jul 3 10:01:00 GMT 2006

Ranjit Mathew writes:
 > 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 --main=Hello -Wl,-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.


./classpath/tools/gnu/classpath/tools/appletviewer/ javax.swing.JOptionPane;
./classpath/tools/gnu/classpath/tools/appletviewer/ javax.swing.JOptionPane;
./classpath/tools/gnu/classpath/tools/appletviewer/ gnu.javax.swing.text.html.parser.HTML_401F;
./classpath/javax/accessibility/ javax.swing.text.AttributeSet;
./classpath/javax/accessibility/ javax.swing.text.AttributeSet;
./classpath/javax/accessibility/ javax.swing.text.AttributeSet;
./classpath/gnu/xml/dom/html2/ javax.swing.text.AttributeSet;
./classpath/gnu/xml/dom/html2/ javax.swing.text.html.HTML;
./classpath/gnu/xml/dom/html2/ javax.swing.text.html.parser.DTD;
./classpath/gnu/xml/dom/html2/ javax.swing.text.html.parser.TagElement;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JButton;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JDialog;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JLabel;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JList;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JPanel;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JPasswordField;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JScrollPane;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JTextArea;
./classpath/gnu/javax/security/auth/callback/ javax.swing.JTextField;
./classpath/gnu/javax/security/auth/callback/ javax.swing.ListSelectionModel;
./classpath/gnu/javax/print/ javax.swing.BorderFactory;
./classpath/gnu/javax/print/ javax.swing.Box;
./classpath/gnu/javax/print/ javax.swing.BoxLayout;
./classpath/gnu/javax/print/ javax.swing.ButtonGroup;
./classpath/gnu/javax/print/ javax.swing.JButton;
./classpath/gnu/javax/print/ javax.swing.JCheckBox;
./classpath/gnu/javax/print/ javax.swing.JComboBox;
./classpath/gnu/javax/print/ javax.swing.JDialog;
./classpath/gnu/javax/print/ javax.swing.JLabel;
./classpath/gnu/javax/print/ javax.swing.JPanel;
./classpath/gnu/javax/print/ javax.swing.JRadioButton;
./classpath/gnu/javax/print/ javax.swing.JSpinner;
./classpath/gnu/javax/print/ javax.swing.JTabbedPane;
./classpath/gnu/javax/print/ javax.swing.JTextField;
./classpath/gnu/javax/print/ javax.swing.SpinnerNumberModel;
./classpath/gnu/javax/print/ javax.swing.border.TitledBorder;
./classpath/gnu/javax/print/ javax.swing.event.ChangeEvent;
./classpath/gnu/javax/print/ javax.swing.event.ChangeListener;
./classpath/java/awt/ javax.swing.text.AttributeSet;
./classpath/java/awt/event/ javax.swing.JScrollPane;
./classpath/java/awt/event/ javax.swing.Scrollable;
./classpath/java/awt/im/spi/ javax.swing.JFrame;

More information about the Java mailing list