[llvm-branch-commits] [llvm] [DirectX] Add `split-section` to `llvm-objcopy` and implement it for `DXContainer` (PR #153265)

James Henderson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 18 01:39:28 PDT 2025


jh7370 wrote:

> > Rather than a new option, I'd rather you just add support for `--only-section` and `--dump-section`, which can then be specified in conjunction with each other to achieve the same result. IIRC, a while back, `--split-dwo` was considered a mistake, because the same effect could be achieved by specifying `--extract-dwo` and `--strip-dwo` and `--split-dwo` doesn't exist in GNU objcopy (which we aim for broad compatibility with).
> 
> I assume you mean `--remove-section` and `--dump-section`. The issue for our use-case is that `--dump-section` only outputs the section contents, it does not output a valid object with just one section specified.

No, I mean `--only-section`, which you'd use in one run, and then a separate `--remove-section` invocation removing that same section.

> We thought it best not to have a different implementation of `dump-section` for `DXContainer` that outputs more than just the contents.

Yes, agreed with this.

> The concern that I have with this is that if we want to take an input file that has 8 sections, pull 3 out into their own files and leave the remaining 5, can we do that without invoking `objcopy` 4 times?
> 
> My reading of the current options is that to do what I described above we would need to invoke objcopy multiple times like:
> 
> ```
> llvm-objcopy <input object> --only-section=RTS0 <path to new signature>
> llvm-objcopy <input object> --only-section=STAT <path to new reflection>
> llvm-objcopy <input object> --only-section=ILDB <path to new debug info>
> llvm-objcopy <input object> --remove-section=RTS0 --remove-section=STAT --remove-section=ILDB <path to stripped file>
> ```

Thanks for the further explanation. Yes, that is what you'd need to do.

> It does seem like we should support the `--only-section` and `--remove-section` options (and maybe that's where we should start), but it would be really nice if we could reduce the number of process launches and times reading the input object file.

Fair enough. My instinct is that a more "objcopy" way of doing things would be to have an option similar to `--dump-section`, which wraps it in the necessary object metadata, without removing the section from the file, which can be combined with `--remove-section` to also remove it. So the above becomes something like:
```
llvm-objcopy <input object> --split-section=RTS0=rts0.o --split-section=STAT=stat.o --split-section=ILDB=ildb.o --remove-section=RTS0 --remove-section=STAT --remove-section=ILDB
```

I've used `--split-section` as the name here, but I'd probably actually consider `--extract-section` as the name, since it's more akin to `--extract-dwo` than `--split-dwo` at this point, but I'm open to suggestions.

@MaskRay, do you have any thoughts on the best way to approach this?

https://github.com/llvm/llvm-project/pull/153265


More information about the llvm-branch-commits mailing list