[PATCH] D35809: [LTO] Make sure symbol ordering is honoured

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 12:11:10 PDT 2017


LGTM, but please add data-sections in a followup patch too.

Cheers,
Rafael

Davide Italiano via Phabricator <reviews at reviews.llvm.org> writes:

> davide created this revision.
> Herald added subscribers: inglorion, emaste.
>
> We do this emitting a section for every function when LTO is used.
> See the discussion in https://bugs.llvm.org/show_bug.cgi?id=33888
>
> I'll follow up with a similar change to the gold plugin. Other formats can probably do the same.
>
>
> https://reviews.llvm.org/D35809
>
> Files:
>   ELF/LTO.cpp
>   test/ELF/lto/Inputs/symbol-ordering-lto.ll
>   test/ELF/lto/symbol-ordering-lto.s
>
>
> Index: test/ELF/lto/symbol-ordering-lto.s
> ===================================================================
> --- /dev/null
> +++ test/ELF/lto/symbol-ordering-lto.s
> @@ -0,0 +1,25 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-scei-ps4 %s -o %t.o
> +# RUN: llvm-as %p/Inputs/symbol-ordering-lto.ll -o %t.bc
> +
> +# Set up the symbol file
> +# RUN: echo "tin  " > %t_order_lto.txt
> +# RUN: echo "_start " >> %t_order_lto.txt
> +# RUN: echo "pat " >> %t_order_lto.txt
> +
> +# RUN: ld.lld --symbol-ordering-file %t_order_lto.txt %t.o %t.bc -o %t2.out
> +# RUN: llvm-readobj -elf-output-style=GNU -t %t2.out| FileCheck %s
> +
> +# Check that the order is pat -> _start -> tin.
> +
> +# CHECK: Symbol table '.symtab' contains 4 entries:
> +# CHECK-NEXT:   Num:    Value          Size Type    Bind   Vis      Ndx Name
> +# CHECK-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
> +# CHECK-NEXT:     1: 0000000000201008     0 NOTYPE  GLOBAL DEFAULT    1 _start
> +# CHECK-NEXT:     2: 0000000000201020     6 FUNC    GLOBAL DEFAULT    1 pat
> +# CHECK-NEXT:     3: 0000000000201000     6 FUNC    GLOBAL DEFAULT    1 tin
> +
> +.globl _start
> +_start:
> +  call pat
> +  call tin
> Index: test/ELF/lto/Inputs/symbol-ordering-lto.ll
> ===================================================================
> --- /dev/null
> +++ test/ELF/lto/Inputs/symbol-ordering-lto.ll
> @@ -0,0 +1,10 @@
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-scei-ps4"
> +
> +define i32 @tin() {
> +  ret i32 22
> +}
> +
> +define i32 @pat() {
> +  ret i32 42
> +}
> Index: ELF/LTO.cpp
> ===================================================================
> --- ELF/LTO.cpp
> +++ ELF/LTO.cpp
> @@ -73,6 +73,9 @@
>    Conf.Options = InitTargetOptionsFromCodeGenFlags();
>    Conf.Options.RelaxELFRelocations = true;
>  
> +  // Always emit a section per function with LTO.
> +  Conf.Options.FunctionSections = true;
> +
>    if (Config->Relocatable)
>      Conf.RelocModel = None;
>    else if (Config->Pic)
>
>
> Index: test/ELF/lto/symbol-ordering-lto.s
> ===================================================================
> --- /dev/null
> +++ test/ELF/lto/symbol-ordering-lto.s
> @@ -0,0 +1,25 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-scei-ps4 %s -o %t.o
> +# RUN: llvm-as %p/Inputs/symbol-ordering-lto.ll -o %t.bc
> +
> +# Set up the symbol file
> +# RUN: echo "tin  " > %t_order_lto.txt
> +# RUN: echo "_start " >> %t_order_lto.txt
> +# RUN: echo "pat " >> %t_order_lto.txt
> +
> +# RUN: ld.lld --symbol-ordering-file %t_order_lto.txt %t.o %t.bc -o %t2.out
> +# RUN: llvm-readobj -elf-output-style=GNU -t %t2.out| FileCheck %s
> +
> +# Check that the order is pat -> _start -> tin.
> +
> +# CHECK: Symbol table '.symtab' contains 4 entries:
> +# CHECK-NEXT:   Num:    Value          Size Type    Bind   Vis      Ndx Name
> +# CHECK-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
> +# CHECK-NEXT:     1: 0000000000201008     0 NOTYPE  GLOBAL DEFAULT    1 _start
> +# CHECK-NEXT:     2: 0000000000201020     6 FUNC    GLOBAL DEFAULT    1 pat
> +# CHECK-NEXT:     3: 0000000000201000     6 FUNC    GLOBAL DEFAULT    1 tin
> +
> +.globl _start
> +_start:
> +  call pat
> +  call tin
> Index: test/ELF/lto/Inputs/symbol-ordering-lto.ll
> ===================================================================
> --- /dev/null
> +++ test/ELF/lto/Inputs/symbol-ordering-lto.ll
> @@ -0,0 +1,10 @@
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-scei-ps4"
> +
> +define i32 @tin() {
> +  ret i32 22
> +}
> +
> +define i32 @pat() {
> +  ret i32 42
> +}
> Index: ELF/LTO.cpp
> ===================================================================
> --- ELF/LTO.cpp
> +++ ELF/LTO.cpp
> @@ -73,6 +73,9 @@
>    Conf.Options = InitTargetOptionsFromCodeGenFlags();
>    Conf.Options.RelaxELFRelocations = true;
>  
> +  // Always emit a section per function with LTO.
> +  Conf.Options.FunctionSections = true;
> +
>    if (Config->Relocatable)
>      Conf.RelocModel = None;
>    else if (Config->Pic)


More information about the llvm-commits mailing list