Skip to content

[CIR][CodeGen] Enable -fno-PIE #940

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 5 commits into from
Oct 9, 2024
Merged

Conversation

bruteforceboy
Copy link
Contributor

The title describes the purpose of the PR.

The logic was gotten from the original CodeGen, and I added a test to check that -fno-PIE is indeed enabled.

Copy link
Collaborator

@smeenai smeenai left a comment

Choose a reason for hiding this comment

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

Thank you! I left a few comments.

@@ -449,7 +449,11 @@ static bool shouldAssumeDSOLocal(const CIRGenModule &CGM,
return false;

if (CGOpts.DirectAccessExternalData) {
llvm_unreachable("-fdirect-access-external-data not supported");
if (auto gv = dyn_cast<mlir::cir::GlobalOp>(GV.getOperation()))
return !gv.getTlsModel().has_value();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is equivalent to the CodeGen code? That one only returns if the var isn't thread-local, but this one always returns. It's equivalent right now because of the way the function is laid out, but if things change in the future, it's probably easier to mirror the existing structure as closely as possible.

I'm linking the corresponding CodeGen code here for reference for everyone: https://github.com/llvm/llvm-project/blob/b2c615fc792c3f75af66aac99c05ffa85ef50354/clang/lib/CodeGen/CodeGenModule.cpp#L1726-L1744

Copy link
Member

Choose a reason for hiding this comment

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

We should probably incorporate the OG cloning assumptions + asserts into the webpage docs, which I was never able to do, just in case you find yourself wanting to update some docs, this could be a good one!

@@ -0,0 +1,3 @@
// RUN: %clang --target=x86_64-unknown-linux-gnu -fclangir %s -fno-PIE -c

void empty(void) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be nice for the test to show the code that's generated for accessing global variables and calling functions with -fno-PIE (ideally we can cover all the new conditions that were added).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a difference in the produced CIR with fno-PIE enabled, or maybe I am wrong? It begs the question of if enabling the flag is enough to add support for this option.

Copy link
Member

@bcardosolopes bcardosolopes Oct 8, 2024

Choose a reason for hiding this comment

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

Since your change is on shouldAssumeDSOLocal, checking whether the CIR and LLVM output contains or doesn't contain the dso stuff is probably the best thing to do here. See clang/test/CIR/CodeGen/abstract-cond.c for an example on how to craft such tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the test!

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

one minor change needed.

@bcardosolopes bcardosolopes merged commit 72f329a into llvm:main Oct 9, 2024
6 checks passed
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
The title describes the purpose of the PR. 

The logic was gotten from the original CodeGen, and I added a test to
check that `-fno-PIE` is indeed enabled.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
The title describes the purpose of the PR. 

The logic was gotten from the original CodeGen, and I added a test to
check that `-fno-PIE` is indeed enabled.
lanza pushed a commit that referenced this pull request Nov 5, 2024
The title describes the purpose of the PR. 

The logic was gotten from the original CodeGen, and I added a test to
check that `-fno-PIE` is indeed enabled.
lanza pushed a commit that referenced this pull request Mar 18, 2025
The title describes the purpose of the PR. 

The logic was gotten from the original CodeGen, and I added a test to
check that `-fno-PIE` is indeed enabled.
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.

4 participants