-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[DirectX] Add boilerplate integration of objcopy
for DXContainerObjectFile
#153079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
44f66db
boiler plate to add dxcontainer to objcopy
inbelic 648d0fc
add basic tests
inbelic c4b1096
self-review: recompute offsets instead of storing them
inbelic a3229ee
review: use dxbc instead of dxc
inbelic 7ca8df7
review: account for endianness on non-copy values
inbelic 56cbd57
review: address LLVM/objcopy guideline comments
inbelic c78cc58
review: allow PreserveDates
inbelic 152c383
review: remove symbol related options
inbelic 99e3b41
review: remove partition related options
inbelic dc8e3c2
self-review: correct header filesize
inbelic 364681a
review: fix up comments
inbelic 4fa61af
review: ensure reader errors are surfaced
inbelic 9a60220
review: fix up comments
inbelic 79c043e
review: rename files
inbelic 40d4594
review: rename test
inbelic c0aec7a
review: assert offsets
inbelic b4c17fb
review: add comment
inbelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===- DXContainerConfig.h --------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_OBJCOPY_DXCONTAINER_DXCONTAINERCONFIG_H | ||
#define LLVM_OBJCOPY_DXCONTAINER_DXCONTAINERCONFIG_H | ||
|
||
namespace llvm { | ||
namespace objcopy { | ||
|
||
// DXContainer specific configuration for copying/stripping a single file. This | ||
// is defined, following convention elsewhere, as the return type of | ||
// `getDXContainerConfig`, which reports an error for an unsupported option. | ||
struct DXContainerConfig {}; | ||
|
||
} // namespace objcopy | ||
} // namespace llvm | ||
|
||
#endif // LLVM_OBJCOPY_DXCONTAINER_DXCONTAINERCONFIG_H |
36 changes: 36 additions & 0 deletions
36
llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===- DXContainerObjcopy.h -------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_OBJCOPY_DXCONTAINER_DXCONTAINEROBJCOPY_H | ||
#define LLVM_OBJCOPY_DXCONTAINER_DXCONTAINEROBJCOPY_H | ||
|
||
namespace llvm { | ||
class Error; | ||
class raw_ostream; | ||
|
||
namespace object { | ||
class DXContainerObjectFile; | ||
} // end namespace object | ||
|
||
namespace objcopy { | ||
struct CommonConfig; | ||
struct DXContainerConfig; | ||
|
||
namespace dxbc { | ||
/// Apply the transformations described by \p Config and \p DXContainerConfig | ||
/// to \p In and writes the result into \p Out. | ||
/// \returns any Error encountered whilst performing the operation. | ||
Error executeObjcopyOnBinary(const CommonConfig &Config, | ||
const DXContainerConfig &, | ||
object::DXContainerObjectFile &In, | ||
raw_ostream &Out); | ||
} // end namespace dxbc | ||
} // end namespace objcopy | ||
} // end namespace llvm | ||
|
||
#endif // LLVM_OBJCOPY_DXCONTAINER_DXCONTAINEROBJCOPY_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===- DXContainerObjcopy.cpp ---------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ObjCopy/DXContainer/DXContainerObjcopy.h" | ||
#include "DXContainerReader.h" | ||
#include "DXContainerWriter.h" | ||
#include "llvm/ObjCopy/CommonConfig.h" | ||
#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h" | ||
|
||
namespace llvm { | ||
namespace objcopy { | ||
namespace dxbc { | ||
|
||
using namespace object; | ||
|
||
static Error handleArgs(const CommonConfig &Config, Object &Obj) { | ||
return Error::success(); | ||
} | ||
|
||
Error executeObjcopyOnBinary(const CommonConfig &Config, | ||
const DXContainerConfig &, | ||
DXContainerObjectFile &In, raw_ostream &Out) { | ||
DXContainerReader Reader(In); | ||
Expected<std::unique_ptr<Object>> ObjOrErr = Reader.create(); | ||
if (!ObjOrErr) | ||
return createFileError(Config.InputFilename, ObjOrErr.takeError()); | ||
Object *Obj = ObjOrErr->get(); | ||
assert(Obj && "Unable to deserialize DXContainer object"); | ||
|
||
if (Error E = handleArgs(Config, *Obj)) | ||
return E; | ||
|
||
DXContainerWriter Writer(*Obj, Out); | ||
if (Error E = Writer.write()) | ||
return createFileError(Config.OutputFilename, std::move(E)); | ||
return Error::success(); | ||
} | ||
|
||
} // end namespace dxbc | ||
} // end namespace objcopy | ||
} // end namespace llvm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===- DXContainerObject.h --------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINEROBJECT_H | ||
#define LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINEROBJECT_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Object/DXContainer.h" | ||
#include <vector> | ||
|
||
namespace llvm { | ||
namespace objcopy { | ||
namespace dxbc { | ||
|
||
using namespace object; | ||
|
||
struct Part { | ||
StringRef Name; | ||
ArrayRef<uint8_t> Data; | ||
|
||
size_t size() const { | ||
return sizeof(::llvm::dxbc::PartHeader) // base header | ||
+ Data.size(); // contents size | ||
} | ||
}; | ||
|
||
struct Object { | ||
::llvm::dxbc::Header Header; | ||
SmallVector<Part> Parts; | ||
|
||
size_t headerSize() const { | ||
return sizeof(::llvm::dxbc::Header) // base header | ||
+ sizeof(uint32_t) * Parts.size(); // part offset values | ||
} | ||
}; | ||
|
||
} // end namespace dxbc | ||
} // end namespace objcopy | ||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINEROBJECT_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===- DXContainerReader.cpp ----------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "DXContainerReader.h" | ||
|
||
namespace llvm { | ||
namespace objcopy { | ||
namespace dxbc { | ||
|
||
using namespace object; | ||
|
||
Expected<std::unique_ptr<Object>> DXContainerReader::create() const { | ||
auto Obj = std::make_unique<Object>(); | ||
Obj->Header = DXContainerObj.getHeader(); | ||
for (const SectionRef &Part : DXContainerObj.sections()) { | ||
DataRefImpl PartDRI = Part.getRawDataRefImpl(); | ||
Expected<StringRef> Name = DXContainerObj.getSectionName(PartDRI); | ||
if (auto E = Name.takeError()) | ||
return E; | ||
assert(Name->size() == 4 && | ||
"Valid DXIL Part name consists of 4 characters"); | ||
Expected<ArrayRef<uint8_t>> Data = | ||
DXContainerObj.getSectionContents(PartDRI); | ||
if (auto E = Data.takeError()) | ||
return E; | ||
Obj->Parts.push_back({*Name, *Data}); | ||
} | ||
return std::move(Obj); | ||
} | ||
|
||
} // end namespace dxbc | ||
} // end namespace objcopy | ||
} // end namespace llvm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===- DXContainerReader.h --------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERREADER_H | ||
#define LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERREADER_H | ||
|
||
#include "DXContainerObject.h" | ||
|
||
namespace llvm { | ||
namespace objcopy { | ||
namespace dxbc { | ||
|
||
using namespace object; | ||
|
||
class DXContainerReader { | ||
public: | ||
explicit DXContainerReader(const DXContainerObjectFile &Obj) | ||
: DXContainerObj(Obj) {} | ||
Expected<std::unique_ptr<Object>> create() const; | ||
|
||
private: | ||
const DXContainerObjectFile &DXContainerObj; | ||
}; | ||
|
||
} // end namespace dxbc | ||
} // end namespace objcopy | ||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERREADER_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.