title: does android-ndk build with --gc-sections, and how to disable?
body: <p>I am porting the 'iw' command to Android.  This is wireless related.  It appears that the iw tool has a set of commands that can be used, however from another user's site: </p>
  
  <blockquote>
    <p>A glance at the iw source revealed that iw sticks all that stuff into
    an ELF section which mostly disappears when you link with
    –gc-sections.</p>
  </blockquote>
  
  <p>This person was porting 'iw' to Android also, but decided to do cross-compilation through make instead of building an Android.mk and building through android-ndk.  He mentions that whenever --gc-sections is removed:</p>
  
  <blockquote>
    <p>So with that exorcised from my linker command line, I finally 
    have a functioning Android iw </p>
  </blockquote>
  
  <p>I am finding this to be true.  Whenever I build 'iw' by constructing an Android.mk, and then running 'iw' on my Android device, all of these commands disappear.  </p>
  
  <p>Here is my Android.mk:</p>
  
  <pre><code>LOCAL_PATH:= $(call my-dir)
  
  include $(CLEAR_VARS)
  
  LOCAL_SRC_FILES:= \
    iw.c \
    genl.c \
    event.c \
    info.c \
    phy.c \
    interface.c \
    ibss.c \
    station.c \
    survey.c \
    util.c \
    mesh.c \
    mpath.c \
    scan.c \
    reg.c \
    version.c \
    reason.c \
    status.c \
    connect.c \
    link.c \
    offch.c \
    ps.c \
    cqm.c \
    bitrate.c \
    wowlan.c \
    roc.c \
    sections.c
  
  
  
  LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lowpan/include \
    $(LOCAL_PATH)/../libnl/include
  
  
  LOCAL_CFLAGS +=  -g
  LOCAL_CFLAGS += -fPIC -DPIC
  
  LOCAL_STATIC_LIBRARIES := libnls libnl
  
  ifeq ($(TARGET_BUILD_TYPE),release)
    LOCAL_CFLAGS += -g
  endif
  
  LOCAL_MODULE:= iw
  
  include $(BUILD_EXECUTABLE)
  </code></pre>
  
  <p>If it is true that the android-ndk is somehow using --gc-sections and removing these commands from an ELF section, I cannot figure out how to stop it from doing this.  Does anyone have any suggestions here?</p>
  
  <hr>
  
  <p>Edit:  It does look like the NDK is using this:</p>
  
  <pre><code>build/core/default-build-commands.mk:    -Wl,--gc-sections \
  build/tools/toolchain-patches/build/0001-Options-brought-in-from-core-combo-for-IA.patch:+  -fexceptions -ffunction-sections -finline-functions \
  build/tools/toolchain-patches/build/0001-Options-brought-in-from-core-combo-for-IA.patch:+  -Wl,-z,noexecstack -Wl,--gc-sections -nostdlib \
  build/tools/toolchain-patches/build/0001-Options-brought-in-from-core-combo-for-IA.patch:+  -fexceptions -frtti -fstrict-aliasing -ffunction-sections -finline-functions  \
  build/tools/toolchain-patches/build/0001-Options-brought-in-from-core-combo-for-IA.patch:+  -ffunction-sections -funwind-tables -fmessage-length=0 \
  toolchains/arm-linux-androideabi-4.4.3/setup.mk:    -ffunction-sections \
  toolchains/arm-linux-androideabi-4.4.3/setup.mk:    -Wl,--gc-sections \
  toolchains/x86-4.4.3/setup.mk:    -ffunction-sections \
  toolchains/x86-4.4.3/setup.mk:    -Wl,--gc-sections \
  </code></pre>
  
  <hr>
  
  <p>EDIT: I removed all instances of --gc-sections and --function-sections from the android-ndk, and after rebuilding it works!  However, I'd prefer not to modify the android-ndk, so there must be a modification to my local Android.mk to remove these two flags.</p>
  
  <hr>
  
  <p>EDIT: I removed only --gc-sections from the above default android-ndk files, and that solved the problem.  So, --function-sections is not related.  I just need to figure out how to disable --gc-sections in a local Android.mk</p>