相关疑难解决方法(0)

__attribute __((构造函数))究竟是如何工作的?

似乎很清楚它应该设置.

  1. 什么时候它运行?
  2. 为什么有两个括号?
  3. __attribute__功能吗?一个宏?句法?
  4. 这在C中有用吗?C++?
  5. 它的工作功能是否需要是静态的?
  6. 什么时候__attribute__((destructor))跑?

目标C中的示例:

__attribute__((constructor))
static void initialize_navigationBarImages() {
  navigationBarImages = [[NSMutableDictionary alloc] init];
}

__attribute__((destructor))
static void destroy_navigationBarImages() {
  [navigationBarImages release];
}
Run Code Online (Sandbox Code Playgroud)

c c++ gcc objective-c

327
推荐指数
4
解决办法
12万
查看次数

Linux如何确定模块初始化调用的顺序?

我有一个带有SPI闪存的设备我想在该闪存设备上使用UBIFS文件系统作为我的rootfs.我面临的问题是UBI模块在SPI模块初始化之前初始化.因此,当UBI加载时,它无法连接到我告诉它的UBI设备(通过内核命令行),因此没有rootfs.下面的控制台输出说明了这一点

我一直潜入源代码,看到它init/main.c有一个do_initcalls()简单地调用函数指针列表的函数.这些函数指针指向module_init()内置于内核的模块的所有功能.这些函数指针放在内核二进制文件的特殊部分中,因此在编译时选择此顺序.但是,我还没弄清楚该命令是如何确定的.

    [    0.482500] UBI error: ubi_init: UBI error: cannot initialize UBI, error -19
    [    0.492500] atmel_spi atmel_spi.0: Using dma0chan0 (tx) and  dma0chan1 (rx) for DMA transfers
    [    0.500000] atmel_spi atmel_spi.0: Atmel SPI Controller at 0xf0000000 (irq 13)
    [    0.507500] m25p80 spi0.1: mx25l25635e (32768 Kbytes)
    [    0.512500] Creating 7 MTD partitions on "jedec_flash":
    [    0.520000] 0x000000000000-0x000000020000 : "loader"
    [    0.527500] 0x000000020000-0x000000060000 : "u-boot"
    [    0.537500] 0x000000060000-0x000000080000 : "u-boot-env"
    [    0.547500] 0x000000080000-0x000000280000 : "kernel0"
    [ …
Run Code Online (Sandbox Code Playgroud)

embedded linux-kernel ubifs

25
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×1

c++ ×1

embedded ×1

gcc ×1

linux-kernel ×1

objective-c ×1

ubifs ×1