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
Align AArch64 and i386 image base to superpage
Summary:
As for x86_64, the default image base for AArch64 and i386 should be
aligned to a superpage appropriate for the architecture.
On AArch64, this is 2 MiB, on i386 it is 4 MiB.
Reviewers: emaste, grimar, javed.absar, espindola, ruiu, peter.smith, srhines, rprichard
Reviewed By: ruiu, peter.smith
Subscribers: jfb, markj, arichardson, krytarowski, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D50297
llvm-svn: 342746
2018-09-22 00:58:13 +08:00
# CHECK- N E X T : 4 0 1 0 0 d : 8 b 8 0 { { . * } } m o v l - 4 ( % 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 ( % 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] 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 : .got 00000004 0 0 0 0 0 0 0 0 0 0 4 0 2 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