簡體   English   中英

Apple:使用 -O0 與 -O2(內核)編譯 clang 幀大小

[英]Apple: Compile clang frame size with -O0 vs -O2 (kernel)

我有一個現有項目,我們為開發人員編譯 DEBUG(和 -O0 所以 lldb 有意義)。 但是我有一個 function 特別是當使用 -O0 時氣球的大小:

-O2 -Wframe-larger-than=100
warning: stack frame size of 168 bytes in function 'dsl_scan_visitbp'
-O0 -Wframe-larger-than=100
warning: stack frame size of 1160 bytes in function 'dsl_scan_visitbp'

並且通過一些遞歸,堆棧可能會非常垃圾(內核中的 16K 堆棧)。

首先要檢查的是任何局部變量,但我相信只有兩個:

        dsl_pool_t *dp = scn->scn_dp;
        blkptr_t *bp_toread = NULL;

If you want to see the whole function: https://github.com/openzfs/zfs/blob/master/module/zfs/dsl_scan.c#L1908 (Linux sources, but dealing with Apple clang port)

那個源文件里有一堆alwaysinline ,可能也來這里玩。

但我很好奇為什么它會隨着 -O0 變大?

然后該怎么辦,我看不到任何Apple-clang #pragmas在一個function或一個文件的源文件中打開“優化”(僅關閉優化)。 如果我知道原因是什么,也許我可以用不同的編譯指示來控制那個特定的問題。

我現在看到的唯一解決方案是讓dsl_scan.c在 Makefile 中以不同方式處理,以便只有該文件始終獲得 -O2。 但這有點乏味。

我不熟悉代碼庫,所以我看不到任何會占用大量堆棧空間的明顯變量。 但是,我注意到函數(包括always_inline d)很長。 通常,在調試版本中,無論 scope 是什么,都會在堆棧幀中為每個變量和臨時表達式結果分配一個唯一的空間。 因此,即使 2 個變量的生命周期不重疊(例如,一個在if塊中聲明,另一個在else塊中聲明),它們將在 memory 中分配單獨的空間。 所以即使有很多小的短期變量和臨時值,這也會累加。

You are probably best off disabling always_inline attributes in all functions called by this function in debug builds, as this avoids pre-allocating memory for all possible branches of execution even if they are never taken, or if they are declared in a function that's not involved在遞歸中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM