[PATCH] D38260: [llvm-objcopy] Add support for removing sections

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 02:09:40 PDT 2017


jhenderson added a comment.

I did an experiment using objcopy, to see what happened if it removes a SHF_ALLOC section in a linked ELF with segments. As it turns out, objcopy removes the section without warning or error, and leaves 0s in its place. This could be dangerous on x86 at least, I think. If you do this to an executable section, and there's still the ability to jump there, then this could lead to execution of invalid instructions. At the very least, we should write trap instructions in place of the removed section, if it is in the executable segment. Alternatively, I'm quite happy you emit an error in this case.

A possible suggestion might be to have both behaviours, but have the "blank section" behaviour under another switch (e.g. --blank-section). This could be useful if the user wants to send somebody an ELF to inspect some specific characteristics, but without allowing them to actually run the program or see certain bits of data for whatever reason. I'd still replace the section contents with trap instructions in this case.



================
Comment at: test/tools/llvm-objcopy/segment-data-kept.test:3
+# RUN: llvm-objcopy -R .text2 %t %t2
+# RUN: od -t x1 %t2 | FileCheck %s
+
----------------
Why not fold this and segment-test-remove-section.test together?


Repository:
  rL LLVM

https://reviews.llvm.org/D38260





More information about the llvm-commits mailing list