[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #31 from cvs-commit at gcc dot gnu.org --- The binutils-2_28-branch branch has been updated by H.J. Lu: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cff08d0aa476af2142f60ebf78412b0b7ba61eb3 commit cff08d0aa476af2142f60ebf78412b0b7ba61eb3 Author: H.J. Lu Date: Mon Apr 24 09:37:10 2017 -0700 i386: Set ELF_MAXPAGESIZE to 0x1000 for VxWorks commit a27e437177412e5b52999723f3c5d5d0d37b9087 Author: Roland McGrath Date: Thu Jul 28 22:35:15 2011 + BFD vector for elf32-i386-nacl: changed ELF_MAXPAGESIZE to 0x1 for VxWorks. This patch fixes it and updated testsuite/ld-i386/vxworks2.sd to add space for program headers. bfd/ PR ld/21425 * elf32-i386.c (ELF_MAXPAGESIZE): Set to 0x1000 for VxWorks. ld/ PR ld/20815 * testsuite/ld-i386/vxworks2.sd: Add space for program headers. (cherry picked from commit 1587442d37ee4266e54d59bfdc783574f0587aff) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #30 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by H.J. Lu: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1587442d37ee4266e54d59bfdc783574f0587aff commit 1587442d37ee4266e54d59bfdc783574f0587aff Author: H.J. Lu Date: Mon Apr 24 09:37:10 2017 -0700 i386: Set ELF_MAXPAGESIZE to 0x1000 for VxWorks commit a27e437177412e5b52999723f3c5d5d0d37b9087 Author: Roland McGrath Date: Thu Jul 28 22:35:15 2011 + BFD vector for elf32-i386-nacl: changed ELF_MAXPAGESIZE to 0x1 for VxWorks. This patch fixes it and updated testsuite/ld-i386/vxworks2.sd to add space for program headers. bfd/ PR ld/21425 * elf32-i386.c (ELF_MAXPAGESIZE): Set to 0x1000 for VxWorks. ld/ PR ld/20815 * testsuite/ld-i386/vxworks2.sd: Add space for program headers. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 Alan Modra changed: What|Removed |Added CC||amodra at gmail dot com --- Comment #29 from Alan Modra --- For any archaeologists: git commit e9a38e0f5287ce7b4629f5f923191e38dd7355c0 should have been marked with this pr number. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #28 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Nick Clifton: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=502d895cd1ca5d4abf4ef55984cbf5239aeaef0c commit 502d895cd1ca5d4abf4ef55984cbf5239aeaef0c Author: Nick Clifton Date: Wed Nov 30 11:06:42 2016 + Stop readelf from complaining about out of order PT_LOAD segments. PR ld/20815 * readelf.c (process_program_headers): Do not warn about out of order PT_LOAD segments. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #27 from ma.jiang at zte dot com.cn --- (In reply to ma.jiang from comment #26) > (In reply to cvs-com...@gcc.gnu.org from comment #24) > Hi Nick, > Could you please say more about the this? What problems do you encountered > with sorted segments? I really can not understand why non-ordered segments > are needed... Sorry, Just found the dicussion in "https://sourceware.org/ml/binutils/2016-11/msg00338.html;. Are we dealing with the dilemma that user provided a PHDR which is not consistent with the elf spec? I agree that if user has provided PHDRs, we should not do the sorting. Users should have the right to place their segments when they provided the PHDRs themselves. We could just give a warning if user provided PHDRs violated the elf spec. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #26 from ma.jiang at zte dot com.cn --- (In reply to cvs-com...@gcc.gnu.org from comment #24) > The master branch has been updated by Nick Clifton: > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git; > h=cd58485720b47d80fed0b281d15a9198f43eaf0c > > commit cd58485720b47d80fed0b281d15a9198f43eaf0c > Author: Nick Clifton > Date: Mon Nov 28 17:45:22 2016 + > > Partially revert patch for PR 20815 - do not sort the PT_LOAD segments. > Non-ordered segments are needed by the Linux kernel. > > PR ld/20815 > * elf.c (phdr_sorter): Delete. > (assign_file_positions_except_relocs): Do not sort program > headers. Hi Nick, Could you please say more about the this? What problems do you encountered with sorted segments? I really can not understand why non-ordered segments are needed... -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #25 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Nick Clifton: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=157686a88644b111658c661fc225881e75f3b0db commit 157686a88644b111658c661fc225881e75f3b0db Author: Nick Clifton Date: Mon Nov 28 17:51:57 2016 + Update linker tests after partial reversion of PR 20815 patch. PR 20815 * testsuite/ld-elf/loadaddr1.d: Update. * testsuite/ld-powerpc/vle-multiseg-5.d: Update. * testsuite/ld-scripts/phdrs3a.d: Update. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #24 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Nick Clifton: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd58485720b47d80fed0b281d15a9198f43eaf0c commit cd58485720b47d80fed0b281d15a9198f43eaf0c Author: Nick Clifton Date: Mon Nov 28 17:45:22 2016 + Partially revert patch for PR 20815 - do not sort the PT_LOAD segments. Non-ordered segments are needed by the Linux kernel. PR ld/20815 * elf.c (phdr_sorter): Delete. (assign_file_positions_except_relocs): Do not sort program headers. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #23 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Alan Modra: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ae9a1986c8b1e38342a6fe674f7ad1758d8b06f5 commit ae9a1986c8b1e38342a6fe674f7ad1758d8b06f5 Author: Alan Modra Date: Sun Nov 27 20:07:08 2016 +1030 Fix powerpc vle test for sorting of program headers 1a9ccd70f changed the order of headers. PR 20815 * testsuite/ld-powerpc/vle-multiseg-5.d: Update. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 ma.jiang at zte dot com.cn changed: What|Removed |Added Status|RESOLVED|CLOSED --- Comment #22 from ma.jiang at zte dot com.cn --- (In reply to Nick Clifton from comment #20) > Hi Ma, > > Well this has turned out to be a humongous patch. The problem is that > some targets break the ELF rules, so I needed to add special cases for them. > Plus the linker was not detecting all the cases where invalid program > headers were being created. Plus there were lots of test cases in the > linker testsuite that needed fixing. *sigh* Still I have finally finished > the patch and applied it. Please try out the latest development sources and > let me know if you are happy. (You could also close this PR if you are > happy...) > > Cheers > Nick Hi Nick, Thanks. I have checked the committed patch(havn't try the code though), and believe that my problem has get fixed. But I am not very happy ,as you guys have done all the work leaving me no change to "contribute to the community" :) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #21 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Nick Clifton: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7836e407c65761b003bfbcb7ce89947736330a15 commit 7836e407c65761b003bfbcb7ce89947736330a15 Author: Nick Clifton Date: Wed Nov 23 14:57:51 2016 + Adjust linker test for arm-vxworks in wake of patch for PR 20815. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 Nick Clifton changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED --- Comment #20 from Nick Clifton --- Hi Ma, Well this has turned out to be a humongous patch. The problem is that some targets break the ELF rules, so I needed to add special cases for them. Plus the linker was not detecting all the cases where invalid program headers were being created. Plus there were lots of test cases in the linker testsuite that needed fixing. *sigh* Still I have finally finished the patch and applied it. Please try out the latest development sources and let me know if you are happy. (You could also close this PR if you are happy...) Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #19 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Nick Clifton: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1a9ccd70f9a75dc6b48d340059f28ef3550c107b commit 1a9ccd70f9a75dc6b48d340059f28ef3550c107b Author: Nick Clifton Date: Wed Nov 23 11:10:39 2016 + Fix the linker so that it will not silently generate ELF binaries with invalid program headers. Fix readelf to report such invalid binaries. PR ld/20815 bfd * elf.c (elf_modify_segment_map): Allow empty LOAD segments if they contain the program headers. (_bfd_elf_map_sections_to_segments): If the linker created the PHDR segment then always attempt to include it in a LOAD segment. (assign_file_positions_for_non_load_sections): Allow LOAD segments to overlap PHDR segments. (phdr_sorter): New function. Sorts program headers. (assign_file_positions_except_relocs): Sort the program headers before writing them out. Issue an error if the PHDR segment is not covered by a LOAD segment, unless the backend allows it. * elf-bfd.h (struct elf_backend_data): Add elf_backend_allow_non_load_phdr. * elfxx-target.h (elf_backend_allow_non_load_phdr): Provide default definition that returns FALSE. (elfNN_bed): Initialise the elf_backend_allow_non_load_phdr field. * elf64-hppa.c (elf64_hppa_allow_non_load_phdr): New function. Returns TRUE. (elf_backend_allow_non_load_phdr): Define. * elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Do not place the interpreter string into the .interp section if the nointerp flag is set in the link info structure. * elf32-arc.c (elf_arc_size_dynamic_sections): Likewise. * elf32-score7.c (score_elf_final_link_relocate): Allow for the _gp symbol not being part of the output. binutils* readelf.c (process_program_headers): Check PT_LOAD and PT_PHDR segments for validity. ld * ld.texinfo: Note that PT_TLS can be used as a segment type. * testsuite/ld-discard/discard.ld: Add space for program headers. * testsuite/ld-elf/flags1.ld: Likewise. * testsuite/ld-elf/maxpage3.t: Likewise. * testsuite/ld-elf/noload-1.t: Likewise. * testsuite/ld-elf/orphan.ld: Likewise. * testsuite/ld-elf/overlay.t: Likewise. * testsuite/ld-elf/pr14052.t: Likewise. * testsuite/ld-elf/pr19539.t: Likewise. * testsuite/ld-elf/provide-hidden-1.ld: Likewise. * testsuite/ld-elf/provide-hidden-s.ld: Likewise. * testsuite/ld-elf/weak-dyn-1.ld: Likewise. * testsuite/ld-i386/pr19539.t: Likewise. * testsuite/ld-scripts/defined.t: Likewise. * testsuite/ld-scripts/defined6.t: Likewise. * testsuite/ld-scripts/dynamic-sections.t: Likewise. * testsuite/ld-scripts/empty-aligned.t: Likewise. * testsuite/ld-scripts/provide-2.t: Likewise. * testsuite/ld-scripts/provide-4.t: Likewise. * testsuite/ld-vax-elf/plt-local.ld: Likewise. * testsuite/ld-x86-64/pr19539.t: Likewise. * testsuite/ld-elf/ehdr_start-missing.d: Do not initialise the dynamic linker. * testsuite/ld-elf/ehdr_start-weak.d: Likewise. * testsuite/ld-elf/elf.exp (pr14170, pr17068): Likewise. * testsuite/ld-elf/loadaddr1.d: Update expected readelf output. * testsuite/ld-elf/noload-2.d: Likewise. * testsuite/ld-powerpc/vxworks2.sd: Likewise. * testsuite/ld-scripts/phdrs3a.d: Likewise. * testsuite/ld-scripts/size-2.d: Likewise. * testsuite/ld-elf/group.ld: Add program headers. * testsuite/ld-elf/overlay.d: Skip for SPU. * testsuite/ld-elf/flags1.d: Skip for RX. * testsuite/ld-elf/pr19162.d: Skip for HPPA64. * testsuite/ld-elf/pr19539.d: Skip for ALPHA. * testsuite/ld-scripts/empty-orphan.t: Update program headers. * testsuite/ld-scripts/size-2.t: Likewise. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #18 from ma.jiang at zte dot com.cn --- (In reply to Nick Clifton from comment #17) Hi Nick, I have tested the proposed patch. And yes, it does print error messages as expected, thanks! I only have two small question about the details. Firstly, the patch seem to agree with "the PHDR segment should be in the first load segment, if existed." in logic. But the comments and error messages are somewhat obscure. Secondly, the final error reason "File format not recognized" looks strange. should we add a "bfd_set_error (bfd_error_bad_value)"? -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #17 from Nick Clifton --- Created attachment 9648 --> https://sourceware.org/bugzilla/attachment.cgi?id=9648=edit Proposed (linker) patch Hi Ma, Right - please try out this patch and let me know if it does what you want. The patch includes some fixups to various linker tests that would otherwise trigger the new error message. I am still running local regression tests however, so more fixups may be needed in the final version of the patch. Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #16 from Nick Clifton --- Hi Ma, > The next step is to reproduce the problem locally so that it can be > investigated. This is where I am currently having problems. Never mind - I have found a way to reproduce the problem. Investigating solutions now -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #15 from Nick Clifton --- Created attachment 9646 --> https://sourceware.org/bugzilla/attachment.cgi?id=9646=edit Proposed patch Hi Ma, OK - now we are getting somewhere. So - I have uploaded a patch to readelf which will allow it to detect and report invalid PT_PHDR segments. With this we can now detect broken binaries. The next step is to reproduce the problem locally so that it can be investigated. This is where I am currently having problems. I tried compiling the test.c file as you suggested (gcc -c test.c; ld test.o -T pad.ld) but this produced an output file like the one I uploaded - ie without a PT_PHDR segment. So there must be something different about our build environments. I am going to assume that the version of gcc being used is irrelevant, so it must be the linker. I have been using a version built from the latest development sources and configured for an x86_64-pc-linux-gnu target. What are you using ? Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #14 from ma.jiang at zte dot com.cn --- (In reply to Nick Clifton from comment #13) Hi Nick, now that the generated elf have a PT_PHDR segment, it must load the program header into memory, as the elf standard said clearly "Moreover, it may occur *ONLY IF* the program header table is part of the *MEMORY IMAGE* of the program". The program header table is not in any load segment of the invalid elf, so it is clear that the program header table is not part of the memory image of the elf file. I did not understand all the pricinples behind the elf standard.But,it seems to me "the existence of PT_PHDR is to tell others that you can find the program header table in the memory at the VMA specified by the PHDR segment". If it's not the case, I can not understand why we need a PT_PHDR segment. Anyway, the program header table can be read out from the elf file directly(with the guide of e_phoff). > OK - well if we can will. Provided that we do not break anything else of > course. Thanks,I believe we can make it. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #13 from Nick Clifton --- Hi Ma, > I create my elf using "gcc test.c pad.ld -o > test".My elf do have a PT_PHDR. I have uploaded it,please check. OK, so what is wrong with this test file ? It does have a PT_PHDR segment, but it is the first one in the program header table and it does cover the program headers as they exist in the file. > > But hang on - why would a normal user be creating and using their own linker > > scripts ? > Trust me, there were so many such guys. This problem was reported by a > expert in kernel(not in tool-chain...), when porting some hugepage tests to > mips. Let us give them a hand, :) OK - well if we can will. Provided that we do not break anything else of course. Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #12 from ma.jiang at zte dot com.cn --- Created attachment 9643 --> https://sourceware.org/bugzilla/attachment.cgi?id=9643=edit the invalid elf (In reply to Nick Clifton from comment #11) Hi Nick, I have checked your file. Yes, your elf is OK(as it does not have a PT_PHDR). I have found the way to create your elf on my server(gcc test.c -c; ld test.o pad.ld -o test). I create my elf using "gcc test.c pad.ld -o test".My elf do have a PT_PHDR. I have uploaded it,please check. > > > To tell the truth, it's not hard for me to find what is wrong(LOL). But > > I'm a tool-chain maintainer in my company, and there are a lot of normal > > users who will get totally confused by such problems. > > But hang on - why would a normal user be creating and using their own linker > scripts ? This is something that should be completely hidden from the user, > and something that they never have to worry about (or even know about). Trust me, there were so many such guys.This problem was reported by a expert in kernel(not in tool-chain...), when porting some hugepage tests to mips. Let us give them a hand, :) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #11 from Nick Clifton --- Hi Ma, (In reply to ma.jiang from comment #9) > Yes, the elf standard does not require " the program headers be contained > in a program segment". But, now that the generated elf have a PT_PHDR > segment, it must load the program header into memory, Hang on - I think that we need to check that we agree on the contents of the binary that we are talking about. I have uploaded a compressed a.bad file which is the executable I produced from your test.c source file, linked using the pad.ld linker script. This is the executable that I have been examining, and this executable does not have a PT_PHDR segment. Please could you compare this executable against the one that you are testing, and if they are different (which I suspect will be the case), please could you upload your version. It would also help if you could let me know how you produced that version, as obviously I must have done something different to you. > To tell the truth, it's not hard for me to find what is wrong(LOL). But > I'm a tool-chain maintainer in my company, and there are a lot of normal > users who will get totally confused by such problems. But hang on - why would a normal user be creating and using their own linker scripts ? This is something that should be completely hidden from the user, and something that they never have to worry about (or even know about). Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #10 from Nick Clifton --- Created attachment 9641 --> https://sourceware.org/bugzilla/attachment.cgi?id=9641=edit Compressed a,out that seg-faults -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #9 from ma.jiang at zte dot com.cn --- (In reply to Nick Clifton from comment #8) Hi Nick, Thank you for the explanation.It cost you much time I guess :). It seems that whether the elf is valid become the most important divergence. I still insist it's not valid. > Now an ELF executable *may* elect to > make the program header be part of one of these program segments, in which > case that segment gets the PT_PHDR type and it should be mapped into memory > when the executable is loaded. But - the ELF standard does not require that > the program headers be contained in a program segment. Yes, the elf standard does not require " the program headers be contained in a program segment". But, now that the generated elf have a PT_PHDR segment, it must load the program header into memory, as the elf standard said clearly "Moreover, it may occur *ONLY IF* the program header table is part of the memory image of the program". The PT_PHDR existed, but the program header table is not loaded into memory, thus I insist the generated elf is not valid(if there were no such a PT_PHDR segment, the generated elf is ok). > Of course I realise that this does not help you with the case you > encountered - the linker silently producing a non-working binary. But at > issue here is that the linker script being used was broken, and if you are > using linker scripts then you really need to know what you are doing, and to > expect that you will have to do some deep debugging when things do not work > out as planned. I am sorry, but I really think that in this case the linker > cannot be expected to diagnose the problem for you. To tell the truth, it's not hard for me to find what is wrong(LOL). But I'm a tool-chain maintainer in my company, and there are a lot of normal users who will get totally confused by such problems. I hope the gnu-ld could give a warning at least, even if you do think the elf file is valid. Yes, the man who make mistake should pay the price, but they probably do not know what is wrong...Men are not saints.Let us make the linker more friendly for such guys. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #8 from Nick Clifton --- Hi Ma, (In reply to ma.jiang from comment #6) > First of all , The elf specification does not say very clear about the > first load segment. In my edition > "Tool Interface Standard (TIS) > Executable and Linking Format (ELF) > Specification > Version 1.2", > there is such a sentence: > "The first text page contains the ELF header, the program header table, and > other information." (in the i386 sections ). True - but ... this is describing the *example* layout shown just above (Figure A-4). It is not talking about a mandated file layout. > moreover,the elf specification said > "If it is present,it must precede any loadable segment entry" about the > PT_PHDR segment. True - but we are not dealing with a PR_PHDR segment that is in the wrong place, we are dealing with a program header that is not in any segment at all. At least in the case of the test executable I built the program header starts at 64 bytes into the file and occupies 56 bytes. The first segment however starts at 0x20 bytes into the file, followed by a second one at 0x41 bytes. > Secondly, About the executable generated by the linker, I do NOT think it > is a valid ELF format.The elf specification said "it may occur only if the > program header table is part of the memory image of the program" about the > PT_PHDR segment. Thank goodness,this time the specification said things > clear. The generated executable has a PT_PHDR,but the segment is NOT a part > of memory image of the program. No - you are confusing two things. The program header, which is a region of the file containing entries in the Elf32_Phdr or Elf64_Phdr format, and a program segment which is a region of the file described by one of the entries in the program header itself. Now an ELF executable *may* elect to make the program header be part of one of these program segments, in which case that segment gets the PT_PHDR type and it should be mapped into memory when the executable is loaded. But - the ELF standard does not require that the program headers be contained in a program segment. They can be placed outside of any segment, and at any offset into the file. The only requirement is that, if they exist, they must be indexed by the e_phoff field in the ELF file header, and - by implication - that they do not conflict with any of the other data in the file. So a valid ELF binary can have a program header that is not contained in the first program segment, provided that it is not any of the other segments either. Hence the binary being produced by your test case is a valid ELF binary. Of course I realise that this does not help you with the case you encountered - the linker silently producing a non-working binary. But at issue here is that the linker script being used was broken, and if you are using linker scripts then you really need to know what you are doing, and to expect that you will have to do some deep debugging when things do not work out as planned. I am sorry, but I really think that in this case the linker cannot be expected to diagnose the problem for you. Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 H.J. Lu changed: What|Removed |Added CC||hjl.tools at gmail dot com --- Comment #7 from H.J. Lu --- I agree with Nick. Linker does what linker script says. I don't see there is a need to change. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #6 from ma.jiang at zte dot com.cn --- Hi Nick, Thanks for the reply. This is a tricky problem. First of all , The elf specification does not say very clear about the first load segment. In my edition "Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2", there is such a sentence: "The first text page contains the ELF header, the program header table, and other information." (in the i386 sections ). So, I guess "the first load segment should contain program headers" is right at least for a i386-elf target? moreover,the elf specification said "If it is present,it must precede any loadable segment entry" about the PT_PHDR segment. Secondly, About the executable generated by the linker, I do NOT think it is a valid ELF format.The elf specification said "it may occur only if the program header table is part of the memory image of the program" about the PT_PHDR segment. Thank goodness,this time the specification said things clear. The generated executable has a PT_PHDR,but the segment is NOT a part of memory image of the program. lastly, about the patch. I feel sorry that it breaks many tests.Obviously, the patch need much more work. Maybe we should make it a warning instead of a fatal error? I am very glad to improve the patch, after we both agree with the final plan. There are some important divergences anyway (does the elf required the first load segment things? target specific or general?warnings or errors?). -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #5 from Nick Clifton --- Hi Ma, Thanks for the unpacked files. With those I was able to reproduce the problem, although I am not at all sure yet that it actually represents a problem in the linker. First of all, you state that the ELF specification requires that the program header should be part of the first loadable segment. Can you tell me exactly where in the standard this is stated ? I had a look myself and could not find any such requirement. You see, as far as I can tell the executable generated by the linker *is* a valid ELF format file. It does not work, true, but that is because the kernel is expecting the program headers to be contained in (one of|the first) program segment. But this is not a requirement of the ELF standard. So instead the fault lies squarely with the linker script being used. The linker just did what it was told to do. I do agree however that the linker does have some knowledge of the target environment for which it is creating binaries, so in theory at least, it ought to be able to check that it is generating a valid binary. But this is target specific knowledge, not generic, and as such a patch should be in target specific code (eg bfd/elf64-x86-64.c) rather than generic code (bfd/elf.c). A second problem with your patch is that, whilst it does work for the test case in this PR, it breaks a lot of other tests in the linker testsuite. Now it may be that these tests are "wrong" in the sense that they are not generating binaries that can be executed, and instead they are just intended to test a linker feature, but even so having them fail is not acceptable. All of which leads me to ask if you would consider rewriting your patch so that it is target specific and does not break other linker tests ? Cheers Nick -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #4 from ma.jiang at zte dot com.cn --- Created attachment 9633 --> https://sourceware.org/bugzilla/attachment.cgi?id=9633=edit a dummy main.c to reproduce the bug -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #3 from ma.jiang at zte dot com.cn --- Created attachment 9632 --> https://sourceware.org/bugzilla/attachment.cgi?id=9632=edit linker script to reproduce the bug it seems that my zip can not be open by others(but ok by me...),so re-upload each files seperately. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 --- Comment #2 from ma.jiang at zte dot com.cn --- Created attachment 9631 --> https://sourceware.org/bugzilla/attachment.cgi?id=9631=edit patch to fix the bug it seems that my zip can not open by others(but ok by me...),so re-upload each files seperately -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/20815] throw errors for invalid load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=20815 Nick Clifton changed: What|Removed |Added CC||nickc at redhat dot com --- Comment #1 from Nick Clifton --- (In reply to ma.jiang from comment #0) > Attached "segment-check.patch" adds a check in make_mapping(in elf.c) , it > should be enough to fix the bug. When I try to unzip the attachment I get: Archive: attach.zip End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. Could you upload the attachment again please ? -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils