From da081bbd0a299ff841f3630049c008b072d8b0d0 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 14 Oct 2024 04:20:18 -0700 Subject: [PATCH] (WIP) rewriter: add `__attribute__((visibility("default"))` to `IA2_FN` address taken functions if they don't already default visibility --- tools/rewriter/SourceRewriter.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/rewriter/SourceRewriter.cpp b/tools/rewriter/SourceRewriter.cpp index 4820d1004..aeb52ffbc 100644 --- a/tools/rewriter/SourceRewriter.cpp +++ b/tools/rewriter/SourceRewriter.cpp @@ -686,6 +686,22 @@ class FnPtrExpr : public RefactoringCallback { } } + if (fn_decl->getVisibility() != clang::Visibility::DefaultVisibility) { + auto decl_start = fn_decl->getBeginLoc(); + if (!decl_start.isFileID()) { + llvm::errs() << "Error: non-file loc for function " << fn_name << '\n'; + } else { + llvm::errs() << "trying to add __attribute__((visibility(\"default\"))) for " << fn_name << '\n'; + Replacement old_used_attr(sm, decl_start, 0, + llvm::StringRef("__attribute__((visibility(\"default\"))) ")); + Replacement used_attr = replace_new_file(filename, old_used_attr); + auto err = file_replacements[filename].add(used_attr); + if (err) { + llvm::errs() << "Error adding replacements: " << err << '\n'; + } + } + } + // This check must come after modifying the maps in this pass but before the // Replacement is added if (in_fn_like_macro(loc, sm)) {