強制空 section

  • 強制編譯空的section

    • 說明

      • 一般默認如果一個section沒有內容是不會創建的。
    • 不過不知道最新的ld,gcc有沒有修改。

    • 強制

      • . = 0, . = . + 0, . = sym, . = . + sym and . = ALIGN (. != 0, expr, 1)
      • . = .
  • 案例

    • 環境

      • centos 7,gcc 4.8.5
    • 代碼test.c

      int main() {
         asm("movl $42, %ebx \n\t"
             "movl $1 , %eax \n\t"
             "int $0x80      \n\t");
      }
      
    • makefile

      .PHONY:all clean
      
      ENTRY=-e main
      
      all:
             gcc -fno-builtin -c test.c -o test.o -g
             ld -T link.lds test.o -g -o ad.out $(ENTRY)
      
      clean:
             rm -f test.o *.out
      
    • link腳本

      SECTIONS
      {
        .text 0x400404 : { *(.text) }
        .empty : { . = . ; }
      }
      
  • 發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章