I got /usr/local/bin/ld:arch/ia64/kernel/gate.lds:898: PHDRS and FILEHDR are only permitted for the first PT_LOAD segment
Created attachment 4260 [details] A testcase for Linux/ia64 Working linker: [hjl@gnu-14 kernel]$ ld -o gate-syms.o -T gate.lds gate.o [hjl@gnu-14 kernel]$ ld -shared -s -soname=linux-gate.so.1 -o gate.so -T gate.lds gate.o [hjl@gnu-14 kernel]$ readelf -l gate.so Elf file type is DYN (Shared object file) Entry point 0xa000000000010640 There are 4 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0xa000000000000000 0xa000000000000000 0x0000000000000610 0x0000000000000610 R 10000 LOAD 0x0000000000000000 0xa000000000010000 0xa000000000010000 0x00000000000009b0 0x00000000000009b0 E 10000 DYNAMIC 0x0000000000000268 0xa000000000000268 0xa000000000000268 0x0000000000000140 0x0000000000000140 R 8 IA_64_UNWIND 0x00000000000005c8 0xa0000000000005c8 0xa0000000000005c8 0x0000000000000048 0x0000000000000048 R 8 Section to Segment mapping: Segment Sections... 00 .hash .dynsym .dynstr .gnu.version .gnu.version_d .dynamic .data.patch .IA_64.unwind_info .IA_64.unwind 01 .text 02 .dynamic 03 .IA_64.unwind [hjl@gnu-14 kernel]$ Bad linker: [hjl@gnu-14 kernel]$ ./ld -o gate-syms.o -T gate.lds gate.o./ld:gate.lds:898: PHDRS and FILEHDR are only permitted for the first PT_LOAD segment [hjl@gnu-14 kernel]$ ./ld -shared -s -soname=linux-gate.so.1 -o gate.so -T gate.lds gate.o ./ld:gate.lds:898: PHDRS and FILEHDR are only permitted for the first PT_LOAD segment [hjl@gnu-14 kernel]$
It is caused by http://sourceware.org/ml/binutils-cvs/2009-10/msg00056.html
The reasons ia64 kernel does are 1. EPC segment has to be marked PF_X without PF_R. 2. We can only have one PT_LOAD segment in vDSO. ia64 kernel uses PHDRS { readable PT_LOAD FILEHDR PHDRS FLAGS(4); /* PF_R */ epc PT_LOAD FILEHDR PHDRS FLAGS FLAGS(1); /* PF_X */ dynamic PT_DYNAMIC FLAGS(4); /* PF_R */ unwind 0x70000001; /* PT_IA_64_UNWIND, but ld doesn't match the name */ } so that ld.so can treat readable and epc segments as a single segment with data and text. ld.so can map a single segment with data and text parts.
A patch is posted at http://sourceware.org/ml/binutils/2009-10/msg00182.html
Subject: Bug 10744 CVSROOT: /cvs/src Module name: src Changes by: amodra@sourceware.org 2009-10-08 01:00:27 Modified files: ld : ChangeLog ldlang.c ld.texinfo Log message: PR ld/10744 * ldlang.c (lang_new_phdr): Allow FILEHDR/PHDRS on more than the first PT_LOAD header. * ld.texinfo: Update. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2059&r2=1.2060 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&r1=1.321&r2=1.322 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ld.texinfo.diff?cvsroot=src&r1=1.249&r2=1.250
Subject: Bug 10744 CVSROOT: /cvs/src Module name: src Changes by: amodra@sourceware.org 2009-10-08 01:11:57 Modified files: ld/testsuite : ChangeLog ld/testsuite/ld-scripts: phdrs3.d Log message: PR ld/10744 * ld-scripts/phdrs3.d: Update. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1178&r2=1.1179 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3.d.diff?cvsroot=src&r1=1.1&r2=1.2
patch applied
Subject: Bug 10744 CVSROOT: /cvs/src Module name: src Changes by: hjl@sourceware.org 2009-10-08 02:38:26 Modified files: ld/testsuite : ChangeLog ld/testsuite/ld-scripts: phdrs3.exp Added files: ld/testsuite/ld-scripts: phdrs3a.d phdrs3a.t Log message: 2009-10-07 H.J. Lu <hongjiu.lu@intel.com> PR ld/10744 * ld-scripts/phdrs3.exp: Run phdrs3a. * ld-scripts/phdrs3a.d: New. * ld-scripts/phdrs3a.t: Likewise. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1179&r2=1.1180 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3a.d.diff?cvsroot=src&r1=NONE&r2=1.1 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3a.t.diff?cvsroot=src&r1=NONE&r2=1.1 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/phdrs3.exp.diff?cvsroot=src&r1=1.1&r2=1.2