2017-04-08 14:14:14 +08:00
# REQUIRES : x8 6
# # i3 8 6 - g o t 3 2 x - b a s e l e s s . e l f i s a f i l e p r o d u c e d u s i n g G N U a s v . 2 . 2 7
# # using f o l l o w i n g c o d e a n d c o m m a n d l i n e :
# # ( as - - 3 2 - o b a s e . o b a s e . s )
# #
# # .text
# # .globl foo
# # .type foo, @function
# # foo :
# # nop
# #
# # _start :
# # movl f o o @GOT, %eax
# # movl f o o @GOT, %ebx
# # movl f o o @GOT(%eax), %eax
# # movl f o o @GOT(%ebx), %eax
# #
# # Result f i l e c o n t a i n s f o u r R _ 3 8 6 _ G O T 3 2 X r e l o c a t i o n s . G e n e r a t e d c o d e
# # is a l s o a f o u r m o v i n s t r u c t i o n s . A n d f i r s t t w o h a s n o b a s e r e g i s t e r :
# # < _ start> :
# # 1 : 8 b 0 5 0 0 0 0 0 0 0 0 m o v 0 x0 ,% e a x
# # 7 : 8 b 1 d 0 0 0 0 0 0 0 0 m o v 0 x0 ,% e b x
# # d : 8 b 8 0 0 0 0 0 0 0 0 0 m o v 0 x0 ( % e a x ) ,% e a x
# # 13 : 8 b 8 3 0 0 0 0 0 0 0 0 m o v 0 x0 ( % e b x ) ,% e a x
# #
# # R_ 3 8 6 _ G O T 3 2 X i s c o m p u t e d a s G + A - G O T , b u t i f i t u s e d w i t h o u t b a s e
# # register, i t s h o u l d b e c a l c u l a t e d a s G + A . U s i n g w i t h o u t b a s e r e g i s t e r
# # is o n l y a l l o w e d f o r n o n - P I C c o d e .
# #
# RUN : ld. l l d % S / I n p u t s / i 3 8 6 - g o t 3 2 x - b a s e l e s s . e l f - o % t 1
# RUN : llvm- o b j d u m p - s e c t i o n - h e a d e r s - d % t 1 | F i l e C h e c k % s
# # 7 3 7 2 8 = = 0 x1 2 0 0 0 = = A D D R ( . g o t )
# CHECK : _start :
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)
The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.
Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data
Other advantages:
* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
simplifies binary manipulation tools.
GNU strip before 2.31 discards PT_GNU_RELRO if its
address is not equal to the start of its associated PT_LOAD.
This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
(start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
(https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
can improve on this regard if we'd like to.
Reviewers: ruiu, espindola, pcc
Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert
Differential Revision: https://reviews.llvm.org/D56828
llvm-svn: 356117
2019-03-14 11:47:45 +08:00
# CHECK- N E X T : 4 0 1 0 0 1 : 8 b 0 5 { { . * } } m o v l 4 2 0 2 4 9 6 , % e a x
# CHECK- N E X T : 4 0 1 0 0 7 : 8 b 1 d { { . * } } m o v l 4 2 0 2 4 9 6 , % e b x
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
# CHECK- N E X T : 4 0 1 0 0 d : 8 b 8 0 { { . * } } m o v l - 4 0 9 6 ( % e a x ) , % e a x
# CHECK- N E X T : 4 0 1 0 1 3 : 8 b 8 3 { { . * } } m o v l - 4 0 9 6 ( % e b x ) , % e a x
2017-04-08 14:14:14 +08:00
# CHECK : Sections :
2019-01-28 23:03:47 +08:00
# CHECK : Name S i z e V M A
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
# CHECK : .got .plt 0000000c 0 0 0 0 0 0 0 0 0 0 4 0 3 0 0 0
2017-04-08 14:14:14 +08:00
# RUN : not l d . l l d % S / I n p u t s / i 3 8 6 - g o t 3 2 x - b a s e l e s s . e l f - o % t 1 - p i e 2 > & 1 | \
# RUN : FileCheck % s - - c h e c k - p r e f i x =ERR
2018-03-15 06:05:12 +08:00
# ERR : error : can' t c r e a t e d y n a m i c r e l o c a t i o n R _ 3 8 6 _ G O T 3 2 X a g a i n s t s y m b o l : f o o i n r e a d o n l y s e g m e n t ; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
# ERR : error : can' t c r e a t e d y n a m i c r e l o c a t i o n R _ 3 8 6 _ G O T 3 2 X a g a i n s t s y m b o l : f o o i n r e a d o n l y s e g m e n t ; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output