[lld] r226572 - ELF: Handle sh_addralign being set to zero
Will Newton
will.newton at linaro.org
Tue Jan 20 08:10:04 PST 2015
Author: wnewton
Date: Tue Jan 20 10:10:04 2015
New Revision: 226572
URL: http://llvm.org/viewvc/llvm-project?rev=226572&view=rev
Log:
ELF: Handle sh_addralign being set to zero
sh_addralign of zero is equivalent to sh_addralign of one, meaning
no alignment specified. Avoid calculating Log2 or modulus when
sh_addralign is zero as the results will not be useful.
Added:
lld/trunk/test/elf/sh_addralign.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Atoms.h
Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=226572&r1=226571&r2=226572&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Tue Jan 20 10:10:04 2015
@@ -286,6 +286,9 @@ public:
if ((_symbol->getType() == llvm::ELF::STT_COMMON) ||
_symbol->st_shndx == llvm::ELF::SHN_COMMON) {
return Alignment(llvm::Log2_64(_symbol->st_value));
+ } else if (_section->sh_addralign == 0) {
+ // sh_addralign of 0 means no alignment
+ return Alignment(0, _symbol->st_value);
}
return Alignment(llvm::Log2_64(_section->sh_addralign),
_symbol->st_value % _section->sh_addralign);
Added: lld/trunk/test/elf/sh_addralign.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/sh_addralign.test?rev=226572&view=auto
==============================================================================
--- lld/trunk/test/elf/sh_addralign.test (added)
+++ lld/trunk/test/elf/sh_addralign.test Tue Jan 20 10:10:04 2015
@@ -0,0 +1,38 @@
+# Check handling of section alignment.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor gnu -target arm64 -o %t-exe %t-obj
+# RUN: llvm-objdump -h %t-exe | FileCheck %s
+
+# CHECK: 8 .data 00000000 0000000000402000 DATA
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_AARCH64
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: ''
+ AddressAlign: 0
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+- Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 1
+ Content: ''
+ Size: 0x80000000
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: ''
+ AddressAlign: 4096
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+Symbols:
+ Global:
+ - Name: _start
+ Section: .text
+ Value: 0x0
+ Size: 4
More information about the llvm-commits
mailing list