apple / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. This fork is used to manage Apple’s stable releases of Clang as well as support the Swift project.
https://llvm.org
Other
1.1k stars 320 forks source link

[lldb] [ObjectFileMachO] BSS segments are loadable segments (#96983) #8942

Closed jasonmolenda closed 5 days ago

jasonmolenda commented 5 days ago

ObjectFileMachO::SetLoadAddress sets the address of each segment in a binary in a Target, but it ignores segments that are not loaded in the virtual address space. It was marking segments that were purely BSS -- having no content in the file, but in zero-initialized memory when running in the virtual address space -- as not-loadable, unless they were named "DATA". This works pretty well for typical userland binaries, but in less Darwin environments, there may be BSS segments with other names, that ARE loadable.

I looked at the origin of SectionIsLoadable's check for this, and it was a cleanup by Greg in 2018 where we had three different implementations of the idea in ObjectFileMachO and one of them skipped zero-file-size segments (BSS), which made it into the centralized SectionIsLoadable method.

Also add some logging to the DynamicLoader log channel when loading a binary - it's the first place I look when debugging segment address setting bugs, and it wasn't emitting anything.

rdar://129870649 (cherry picked from commit 91c0ef6f67821eb7298cb05988045e92354ac77b)

jasonmolenda commented 5 days ago

@swift-ci test

jasonmolenda commented 5 days ago

@swift-ci test

jasonmolenda commented 5 days ago

@swift-ci test

jasonmolenda commented 5 days ago

@swift-ci test