没有Android的NDK构建--gc截面,以及如何禁用? [英] does android-ndk build with --gc-sections, and how to disable?

查看:134
本文介绍了没有Android的NDK构建--gc截面,以及如何禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我端起了IW命令到Android。这是无线相关。看来,iw的工具具有一组可使用的命令,但是从另一用户的网站:

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:

在IW源一目了然透露,IW坚持所有的东西进入
  一个ELF节当你与链接,大多消失
  -gc截面。

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.

此人被移植'IW'到Android也有,但是决定做交叉编译通过使建立一个Android.mk和建设,而不是通过Android的NDK。他提到,每当--gc,部分被删除:

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:

因此​​,既然从我的链接器命令行驱除,我终于
  有一个正常的Andr​​oid IW

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

我发现这是真的。每当我建IW我的Andr​​oid设备上构建一个Android.mk,然后运行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.

下面是我的Andr​​oid.mk:

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)

如果这是真的,在Android的NDK以某种方式使用--gc截面和一个ELF部分去除这些命令,我​​无法弄清楚如何从这样停止它。有没有人有什么建议吗?

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?

编辑:它看起来像NDK使用这样的:

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 \


编辑:我移除了Android的NDK --gc截面和--function区段的所有实例,并重建它的作品了!不过,我倒是preFER不要修改的Andr​​oid NDK,所以必须有一个修改我的本地Android.mk删除这两个标志。


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.

编辑:我删除从上面默认的Andr​​oid NDK文件只--gc截面,并解决了这个问题。所以,--function截面无关。我只需要弄清楚如何在本地Android.mk禁用--gc截面

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

推荐答案

您可以添加行

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

你的Andr​​oid.mk文件。但作为结果,您将同时拥有 -gc截面 - 无GC-部分同时指定因为 NDK的构建总是添加 -gc截面可执行文件的选项。

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.

如果这不工作,那么你只有从您的工具链破解 setup.mk 办法。或者你也可以建立一个没有NDK的构建。作为替代变量,我可以建议使用CMake的构建Android的项目。详情请参见 Android的cmake的项目

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

这篇关于没有Android的NDK构建--gc截面,以及如何禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆