Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:23:47+00:00 2026-05-25T06:23:47+00:00

I am porting the ‘iw’ command to Android. This is wireless related. It appears

  • 0

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:

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.

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:

So with that exorcised from my linker command line, I finally
have a functioning Android iw

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.

Here is my Android.mk:

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)

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?


Edit: It does look like the NDK is using this:

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 \

EDIT: I removed all instances of --gc-sections and -ffunction-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.


EDIT: I removed only --gc-sections from the above default android-ndk files, and that solved the problem. So, -ffunction-sections is not related. I just need to figure out how to disable --gc-sections in a local Android.mk

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:23:48+00:00Added an answer on May 25, 2026 at 6:23 am

    You can add line

    LOCAL_LDLIBS += -Wl,--no-gc-sections
    

    to your Android.mk file. But as result you will have both -gc-sections and --no-gc-sections specified at the same time because ndk-build always adds -gc-sections options for executables.

    If this does not work then you have only way to hack setup.mk from your toolchain. Or you can build without ndk-build. As alternative variant I can suggest to use cmake for building Android projects. See android-cmake project for details

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm porting to Android. My existing project has a ton of resource files that
I'm porting a 2d retro game to iPhone that has the following properties: targets
Porting android applications to iphone applications always gives me the following pattern that I
Currently porting an iPhone application to Android. I've encountered an issue that I haven't
I am porting some existing C code to run on Android. This C code
I am porting a game, that was originally written for the Win32 API, to
I'm porting old VB6 code that uses the Winsock control to C#. I haven't
I am porting some functionality from a C++ application to java. This involves reading
I am porting an app that I originally wrote using the accelerometer for IOS
I'm now porting arduino code to stm32(c/c++). Please help me with this function: constrain(x,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.