[PATCH] D55211: [LLD][ELF] - Support discarding the .dynamic section.

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 6 09:19:45 PST 2018


peter.smith added a comment.

I've had a chance to check through this and other 3 patches in series. If we are intending to do the minimum to stop the linker from crashing and assume the user knows what they are doing when they do this, then these look correct to me. I think these changes are important for use of LLD to link the linux kernel.

May I suggest a 4th patch with a test case that shows the scenario from the kernel. This depends on this, D55215 <https://reviews.llvm.org/D55215> and D55218 <https://reviews.llvm.org/D55218>. It illustrates the intent behind the ability to discard these sections. I've made a proposal here:

  # REQUIRES: x86
  # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
  # RUN: echo "SECTIONS { \
  # RUN: .text 0x1000 : { *(.text) } \
  # RUN: .data  : { *(.data) } \
  # RUN: .rela.dyn : { __relocs_start = . ; *(.rela.dyn) *(.rela.*) __relocs_end = . ; } \
  # RUN: /DISCARD/ : { *(.interp) *(.dynsym) *(.dynstr) *(.dynamic) } \
  # RUN: } " > %t.script
  # RUN: ld.lld -pie -o %t --script %t.script %t.o
  # RUN: llvm-readobj --relocs %t | FileCheck -check-prefix=CHECK-RELOCS %s
  # RUN: llvm-readobj --section-headers %t | FileCheck -check-prefix=CHECK-HEADERS %s
  # RUN: llvm-readobj --symbols %t | FileCheck %s
  
  # This test checks a pattern seen in the linux kernel KASLR configuration. There
  # is no dynamic loader to do the relocation or lookup symbols so the
  # kernel relocates itself using only relative non-symbol relocations.
  # As the relocations are located via symbols. The .dynamic, .dynstr and
  # .dynsym can be discarded.
  
  #CHECK-RELOCS: 0x1008 R_X86_64_RELATIVE - 0x1000
  #CHECK-RELOCS: 0x1010 R_X86_64_RELATIVE - 0x1020
  #CHECK-RELOCS: 0x1018 R_X86_64_RELATIVE - 0x1068
  
  #CHECK-HEADERS: .rela.dyn
  #CHECK-HEADERS-NOT: .dynamic
  #CHECK-HEADERS-NOT: .dynstr
          #CHECK-HEADERS-NOT: .dynsym
  
  # CHECK:          Name: __relocs_end
  # CHECK-NEXT:     Value: 0x1068
  # CHECK-NEXT:     Size: 0
  # CHECK-NEXT:     Binding: Global
  # CHECK-NEXT:     Type: None
  # CHECK-NEXT:     Other: 0
  # CHECK-NEXT:     Section: .rela.dyn
  # CHECK-NEXT:   }
  # CHECK-NEXT:   Symbol {
  # CHECK-NEXT:     Name: __relocs_start
  # CHECK-NEXT:     Value: 0x1020
  # CHECK-NEXT:     Size: 0
  # CHECK-NEXT:     Binding: Global
  # CHECK-NEXT:     Type: None
  # CHECK-NEXT:     Other:
  # CHECK-NEXT:     Section: .rela.dyn
  # CHECK-NEXT:   }
  
  
          .text
  
          .globl  _start
          .p2align        4, 0x90
          .type   _start, at function
  _start:
          movq    var at GOTPCREL(%rip), %rax
          retq
  
          .type   var, at object
          .data
          .globl  var
          .globl  __relocs_start
          .globl  __relocs_end
          .p2align        3
  var:
          .quad   _start
          .quad __relocs_start
          .quad __relocs_end




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55211/new/

https://reviews.llvm.org/D55211





More information about the llvm-commits mailing list