gcc.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 10 Feb 2018 01:36:16 +0200
changeset 2229 1a0b6597e594
parent 2228 837f1337c59b
child 2230 9e6ad6607a9e
permissions -rw-r--r--
Mark block quot in HTMLe.

.. -*- coding: utf-8; -*-

=====
 GCC
=====
.. contents::
   :local:

Remove dead code
================

  STRIP_DEAD_CODE = -Wl,-static -fvtable-gc -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-s

``-Wl,-static``
  Link against static libraries. Required for dead-code
  elimination.

``-fvtable-gc``
  C++ virtual method table instrumented with garbage collection
  information for the linker.

``-fdata-sections``
  Keeps data in separate data sections, so they can be discarded
  if unused.

``-ffunction-sections``
  Keeps funcitons in separate data sections, so they can be
  discarded if unused.

``-Wl,--gc-sections``
  Tell the linker to garbage collect and discard unused
  sections.

``-s``
  Strip the debug information, so as to make the code as small
  as possible. (I presume that you'd want to do this in a
  dead-code removal build.)

Map file
========
::

  $ ld -Map=file.map <opts> <files>

or::

  $ gcc -Wl,-Map=file.map <opts> <files>

Predefined macros
=================
::

  $ gcc -arch ppc -dM -E - < /dev/null | sort

Default search path
===================
::

  $ echo | gcc -v -x c -E -

  $ gcc -print-search-dirs
  install: ...
  programs: ...
  libraries: ...

Use ``-###`` in actual invoking::

  $ gcc -### -o foo foo.c

  $ ld --verbose | grep SEARCH_DIR

``LIBRARY_PATH`` and ``LD_LIBRARY_PATH``::

  $ cpp -Wp,-v
  $ cpp -Wp,-lang-c++,-v
  $ cpp -x c++ -Wp,-v