GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Parse both .rela.dyn and .rela.plt of libraries. by krk · Pull Request #1074 · async-profiler/async-profiler

Conversation

@krk

@krk krk commented Dec 6, 2024

Copy link
Copy Markdown
Contributor

It is possible to have symbols in both .rela.dyn and .rela.plt sections, depending how the symbols are used. Furthermore, .rela.dyn can have R_X86_64_64 relocation type among others.

async-profiler did not parse .rela.dyn section if .rela.plt was present.

Support parsing .rela.dyn R_X86_64_64 symbols and both .rela.dyn and .rela.plt in the same ELF binary, to enable internal usage (hooking) of the imported functions.

Related issues

#1060

Motivation and context

While investigating #1060 and the possible fix in #1065, noticed that R_X86_64_64 relocation type is not supported.

How has this been tested?

New test added in symbolsLinuxTest.cpp.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@krk
Parse both .rela.dyn and .rela.plt of libraries.
c9f8c72
Also parse R_X86_64_64 relocations in x86-64 builds.
apangin
apangin reviewed Dec 6, 2024
View reviewed changes

@apangin apangin left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Great job on creating a test case that produces different relocation types in one binary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

krk and swivelmargarita reacted with hooray emoji
All reactions
  • 🎉 2 reactions
Comment thread src/symbols_linux.cpp Outdated
# define R_DIRECT -1
#elif defined(__aarch64__)
# define R_GLOB_DAT R_AARCH64_GLOB_DAT
# define R_DIRECT -1

@apangin apangin Dec 6, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Isn't there an AArch64 equivalent?
I see it generates R_AARCH64_ABS64

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@krk krk Dec 6, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I originally added something for all archs, but given I cannot test them, I focused on x86-64. I can add it for arm64.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/symbols_linux.cpp
} else if (rel != NULL && relsz != 0) {
}

if (rel != NULL && relsz != 0) {

@apangin apangin Dec 6, 2024

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can the same function occur in multiple relocations? I believe it can. We don't necessarily need to handle such cases right now, but if this happens, .rela.plt should take precedence.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

krk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
krk added 3 commits December 6, 2024 16:33
@krk
support R_AARCH64_ABS64
90ae21a
@krk
do not overwrite plt symbols with .rela.dyn
73c334a
@krk
rename tests
e249b92
apangin
apangin reviewed Dec 6, 2024
View reviewed changes
Comment thread src/symbols_linux.cpp Outdated
ElfSymbol* sym = (ElfSymbol*)(symtab + ELF_R_SYM(r->r_info) * syment);
if (sym->st_name != 0) {
_cc->addImport((void**)(base + r->r_offset), strtab + sym->st_name);
_cc->tryAddImport((void**)(base + r->r_offset), strtab + sym->st_name);

@apangin apangin Dec 6, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe just switch the order of these two loops? This will ensure proper precedence automatically without 'override' logic in CodeCache?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

krk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
krk and others added 5 commits December 6, 2024 19:12
@krk
Revert "do not overwrite plt symbols with .rela.dyn"
0684500
This reverts commit 73c334a.
@krk
address comments
3f201b2
@apangin
Merge branch 'master' into reladyn
fefea8d
Signed-off-by: Andrei Pangin <[email protected]>
@apangin
Rename R_DIRECT to R_ABS64
e7e6f17
@apangin
Added comment about .rela.plt & .rela.dyn
f349dc0
Signed-off-by: Andrei Pangin <[email protected]>
@apangin
apangin merged commit 7e57061 into async-profiler:master Dec 7, 2024
This was referenced Dec 7, 2024
Fix #1060 #1065
Closed
Profiler fails to start if both rela.plt and rela.dyn have needed imports #1060
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@apangin apangin apangin left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@krk @apangin
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.