8000 Make dynamic string table simpler to use by partaror · Pull Request #95 · qualcomm/eld · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make dynamic string table simpler to use #95

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

partaror
Copy link
@partaror partaror commented May 16, 2025

Currently, dynamic string table is used as follows:

  1. Before layout: Compute the size of the dynamic string table by
    traversing over dynamic symbols, sonames, DT_NEEDED entries and so
    on.
  2. During output image writing: Again traverse over dynamic symbols,
    sonames, DT_NEEDED entries, ..., This time copy the string into the
    dynamic string table and set the string offset in the dynamic-related
    section that was referring the string.

This separation of computing size, offsets and actually writing makes the dynamic string table use cumbersome and error-prone. Especially for sections such as .gnu.version_r and .gnu.version_d.

With this commit, the dynamic string table can be used as:

std::size_t SONameOffset = FileFormat->addStringToDynStrTab(
    llvm::cast<ELFDynObjectFile>(lib)->getSOName());
auto DTEntry = dynamic()->reserveNeedEntry();
DTEntry->setValue(llvm::ELF::DT_NEEDED, SONameOffset);

There is no need to separate size and offset computation anymore.

Another added benefit is that now we reuse the .dynstr table entries
wherever possible instead of repeating the same string multiple times in
the dynamic string table.

Closes #94

@partaror partaror force-pushed the DynStrTab branch 3 times, most recently from e497dc8 to dbb21f1 Compare May 16, 2025 18:52
return DynamicStringTableContents.size();
}

std::optional<std::size_t> getOffsetInDynStrTab(const std::string &S) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

why std::optional

Copy link
Contributor

Choose a reason for hiding this comment

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

This API is used during image writing step. It expects the string has already been inserted in the dynamic string table. If this is not true, then this API returns an empty optional object (and the user of this API can choose to error/assert as appropriate). It does not add the string in the dynamic string table as the counterpart function addStringToDynStrTab.

Currently, dynamic string table is used as follows:

1) Before layout: Compute the size of the dynamic string table by
   traversing over dynamic symbols, sonames, DT_NEEDED entries and so
   on.
2) During output image writing: Again traverse over dynamic symbols,
   sonames, DT_NEEDED entries, ..., This time copy the string into the
   dynamic string table and set the string offset in the dynamic-related
   section that was referring the string.

This separation of computing size, offsets and actually writing makes
the dynamic string table use cumbersome and error-prone. Especially for
sections such as `.gnu.version_r` and `.gnu.version_d`.

With this commit, the dynamic string table can be used as:

```
std::size_t SONameOffset = FileFormat->addStringToDynStrTab(
    llvm::cast<ELFDynObjectFile>(lib)->getSOName());
auto DTEntry = dynamic()->reserveNeedEntry();
DTEntry->setValue(llvm::ELF::DT_NEEDED, SONameOffset);
```

There is no need to separate size and offset computation anymore.

Another added benefit is that now we reuse the `.dynstr` table entries
wherever possible instead of repeating the same string multiple times in
the dynamic string table.

Closes qualcomm#94

Signed-off-by: Parth Arora <partaror@qti.qualcomm.com>
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.

Dynamic string table is difficult to use because string offsets cannot be computed before layout
3 participants
0