This uses the same input data as for --only-keep-debug. As a contrast, --only-keep-debug truncates the other sections, while --only-section fully removes the other sections.
Details
Diff Detail
Event Timeline
Just to confirm, the desired behaviour of combining certain switches (e.g. --strip-debug and --only-section) is for the explicitly mentioned --only-section section to be kept despite it potentially being removed by the other switch?
Good point - that's the impression I got from reading the structure of handleArgs for ELF, and I hadn't doublechecked until now. However this does seem to be wrong - GNU objcopy returns the intersection of the sets of sections kept by the two options.
Updated to test how --only-section combined with --strip-debug behaves - matching GNU objcopy's behaviour.
test/tools/llvm-objcopy/COFF/only-section.test | ||
---|---|---|
12 | nit: these tests will be a little easier to read if they are indented something like this: SECTIONS: xSections: SECTIONS-NEXT: xIdx Name SECTIONS-DEBUG-NEXT:x .debug_discardable SECTIONS-TEXT-NEXT: x .text SECTIONS-NEXT-EMPTY:x (x's for clarity) | |
21 | I'm not too familiar with using -EMPTY in filecheck, but is this supposed to be SYMBOLS-NEXT-EMPTY? |
test/tools/llvm-objcopy/COFF/only-section.test | ||
---|---|---|
12 | Ok, I can align them. | |
21 | -EMPTY essentially implies -NEXT, it requires the next line to either be empty, or there to be EOF here. I haven't intended to use them combined but apparently I did do that in the paragraph above this. I'll change that one for consistency with the rest (that's the only one I have with NEXT-EMPTY at all). |
-EMPTY essentially implies -NEXT, it requires the next line to either be empty, or there to be EOF here. I haven't intended to use them combined but apparently I did do that in the paragraph above this. I'll change that one for consistency with the rest (that's the only one I have with NEXT-EMPTY at all).
For the record, you can't combine FileCheck suffixes (e.g. CHECK-NEXT-NOT is a NOT using a check prefix of CHECK-NEXT). There are some error checks to catch this, but I don't know how comprehensive they are.
By the way, @jakehehrlich may remember exactly what the intended behaviour is in llvm-objcopy for ELF and combining rules. We discussed it a while back, but I can't remember them exactly, but it was something like explicit section keeps trump implicit section strips, and two explicits are an error. You might want to double-check with him.
Ok. At least for combining --strip-debug with --only-section, the ELF version doesn't match what GNU objcopy does.
I don't have a concrete use/need for --only-section myself so I haven't invested that much thought into it, I only brought it along from the code from ELFObjcopy.cpp that I based the COFF version on.
nit: these tests will be a little easier to read if they are indented something like this:
(x's for clarity)