Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7692 Discussions

Wrong section alignments on linux ELF cause linking problems


We wanted to use the LLVM LLD linker, but it complains about an incorrect section alignment emitted by ICPC. Here is my corresponding bug report to LLVM: . It turns out the bug apparently is within the Intel Compiler. Quoting my bugreport:



I would like to raise this as a feature request for compatibility with GNU LD: LD supports unaligned sections in object files, which are created at least by the Intel ICC compiler and prevents us to adopt LLD in our build. 

   ld: error: .../_moc_mainwindow.o: unaligned data

Further investigation shows

   ~/usr/bin/llvm-readelf -relocations _moc_mainwindow.o

    Relocation section '' at offset 0x2546f contains 1 entries:
     Offset     Info    Type                Sym. Value  Symbol's Name

    Error reading file: unaligned data

This works with GNU LD and GNU GOLD



ICC Version:

icpc (ICC) 15.0.3 20150407

Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

0 Kudos
3 Replies


Please provide us a test case to investigate.




Testcase and Bug:

:~/cpp$ cat main.cpp
int main() { }

:~/cpp$ icpc -c main.cpp

:~/cpp$ llvm-readelf -relocations main.o 

Relocation section '.rel.text' at offset 0x189 contains 1 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name

Error reading file: unaligned data

(notice the unaligned offset 0x189). People from LLVM have provided this technical comment:

"Essentially, all data structures in ELF should be aligned to their natural boundaries both in memory and file: Quote from p.16 "All data structures that the object file format defines follow the "natural" size and alignment guidelines for the relevant class. If necessary, data structures contain explicit padding to ensure 4-byte alignment for 4-byte objects, to force structure sizes to a multiple of 4, and so on. Data also have suitable alignment from the beginning of the file. Thus, for example, a structure containing an Elf32_Addr member will be aligned on a 4-byte boundary within the file."




icpc (ICC) 15.0.3 20150407

You probably use too old compiler.

I tried 15.0.5  Build 20150805 and llvm-readelf built from trunk 6.0 and got the following output:

$ cat main.cpp
int main() {}

$ icpc -V -c main.cpp
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0 Build 20150805
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

$ llvm-readelf -relocations main.o

Relocation section '.rela.text' at offset 0x284 contains 1 entries:
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
0000000000000017  0000000900000002 R_X86_64_PC32          0000000000000000 __intel_new_feature_proc_init - 4

Relocation section '.rela.eh_frame' at offset 0x29c contains 2 entries:
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
0000000000000011  0000000a00000001 R_X86_64_64            0000000000000000 __gxx_personality_v0 + 0
0000000000000028  0000000400000001 R_X86_64_64            0000000000000000 .text + 0

With the recent ICC 18.0 it also works fine.