Skip to content
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

Fix extract_ir.py for macos. #260

Merged
merged 3 commits into from
Jun 11, 2023
Merged

Fix extract_ir.py for macos. #260

merged 3 commits into from
Jun 11, 2023

Conversation

jacob-hegna
Copy link
Collaborator

For whatever reason, the section names for .llvmcmd and .llvmbc are different on macos. One problem is that macos uses macho object files instead of elf, so in addition to the section names there are segment names that need to be specified. The other problem is that regardless of the segments, the section names are different. This patch makes the segment name configurable by a flag, and gives sensible defaults for linux + documentation for macos.

@@ -371,4 +380,5 @@ def main(argv):


if __name__ == '__main__':
multiprocessing.set_start_method('fork')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, meant to include this in the pull request description. it's because of this
abseil/abseil-py#170

basically, the default method of multiprocessing on macos is spawn instead of fork, which means the flags don't get passed around correctly. The flags are accessed within the spawned processes, so without this line macos will use default flag values for anything inside the subprocess.

Comment on lines 81 to 82
'Name of the section name passed to llvm-objcopy. For linux systems, the '
'default .llvmcmd is correct. On macos, one should use __LLVM,__cmdline'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is not about the OS but about the file format (for example, you might be running training on macOS but using binaries compiled for Linux), so I think it's more accurate to say "ELF" and "Mach-O" rather than "Linux" and "macOS" respectively.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed - thanks!

For whatever reason, the section names for .llvmcmd and .llvmbc are different
on macos. One problem is that macos uses macho object files instead of elf, so
in addition to the section names there are segment names that need to be
specified. The other problem is that regardless of the segments, the section
names are different. This patch makes the segment name configurable by a flag,
and gives sensible defaults for linux + documentation for macos.
@jacob-hegna jacob-hegna merged commit 52fa04f into main Jun 11, 2023
@jacob-hegna jacob-hegna deleted the extractir_macos branch June 11, 2023 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants