[PATCH v2][lld] ELF: Handle sh_addralign being set to zero
Shankar Easwaran
shankare at codeaurora.org
Tue Jan 20 08:09:15 PST 2015
LGTM.
On 1/20/2015 4:39 AM, Will Newton wrote:
> On 13 January 2015 at 16:57, Will Newton <will.newton at linaro.org> wrote:
>> 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.
>> ---
>> lib/ReaderWriter/ELF/Atoms.h | 3 +++
>> test/elf/sh_addralign.test | 38 ++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 41 insertions(+)
>> create mode 100644 test/elf/sh_addralign.test
>>
>> Changes in v2:
>> - Added a test
> Ping - is the test ok?
>
>> diff --git a/lib/ReaderWriter/ELF/Atoms.h b/lib/ReaderWriter/ELF/Atoms.h
>> index 23fa3f8..1aed346 100644
>> --- a/lib/ReaderWriter/ELF/Atoms.h
>> +++ b/lib/ReaderWriter/ELF/Atoms.h
>> @@ -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);
>> diff --git a/test/elf/sh_addralign.test b/test/elf/sh_addralign.test
>> new file mode 100644
>> index 0000000..404c676
>> --- /dev/null
>> +++ b/test/elf/sh_addralign.test
>> @@ -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
>> --
>> 2.1.0
>>
>
>
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation
More information about the llvm-commits
mailing list