This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Provide allocator declaration
ClosedPublic

Authored by ddcc on Mar 16 2022, 2:06 PM.

Details

Summary

Ensure that extern allocator declaration is visible before definition

Diff Detail

Event Timeline

ddcc created this revision.Mar 16 2022, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 2:06 PM
ddcc requested review of this revision.Mar 16 2022, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 2:06 PM

Can you please split #include cleanup and the rest?

compiler-rt/lib/scudo/standalone/string_utils.cpp
13

there is memset on :50

compiler-rt/lib/scudo/standalone/vector.h
14

it's used on :46

compiler-rt/lib/scudo/standalone/wrappers_c.h
22

Why do we need this?

ddcc added a comment.Mar 17 2022, 10:55 AM

Do you split want the non-#include changes split out?

compiler-rt/lib/scudo/standalone/string_utils.cpp
13

Same thing, common.h already provides it.

compiler-rt/lib/scudo/standalone/vector.h
14

common.h includes string.h already, so this additional include is unnecessary. We have some custom library paths in our build system, so I needed to go through each include.

compiler-rt/lib/scudo/standalone/wrappers_c.h
22

-Wmissing-variable-declarations complains about no previous extern declaration for Allocator in wrappers_c.cpp, so the intention was to centralize the duplicate extern declarations between wrappers_c.cpp and wrapper_cpp.cpp, but I think that got lost while splitting the commits, and I missed that there's a SCUDO_PREFIX macro here, so I'll just add a declaration to wrappers_c.cpp instead.

ddcc updated this revision to Diff 416251.Mar 17 2022, 10:58 AM

Fix extern declaration of SCUDO_ALLOCATOR

vitalybuka added inline comments.Mar 17 2022, 12:13 PM
compiler-rt/lib/scudo/standalone/vector.h
14

Unless there is a strong reason to do so, I am for IWYU.

ddcc updated this revision to Diff 416584.Mar 18 2022, 12:57 PM

Revert header file removal

compiler-rt/lib/scudo/standalone/vector.h
14

Ok, I've dropped the header removals from this patch

vitalybuka added inline comments.Mar 24 2022, 11:58 AM
compiler-rt/lib/scudo/standalone/wrappers_c.h
22

Cab we move extern to the patch where actually it's necessary?

ddcc added inline comments.Mar 25 2022, 4:50 PM
compiler-rt/lib/scudo/standalone/wrappers_c.cpp
25 ↗(On Diff #416584)

@vitalybuka Are you saying to split this change off into another patch?

vitalybuka added inline comments.Mar 26 2022, 12:47 AM
compiler-rt/lib/scudo/standalone/common.h
120

There is the same in cpp file.
I believe the point was to hide declaration from the header to avoid use by mistake.

compiler-rt/lib/scudo/standalone/wrappers_c.cpp
31–32 ↗(On Diff #416584)

if we need extern, I assumed there is a some new user outside this cpp file.
But I don't see benefits of having extern just before the actual var declaration.

I believe correct approach is how it's done in wrappers_c_bionic.cpp.

Separate patch for unrelated stuff will be nice. Actually each of this fixes better to have as a separate patch with "why" in description.

ddcc added inline comments.Mar 28 2022, 9:53 PM
compiler-rt/lib/scudo/standalone/wrappers_c.cpp
31–32 ↗(On Diff #416584)

The comment above this line seems to suggest that it's not feasible to have separate allocators for C and C++. I did try it and it seemed to work fine locally, but I suspect there may be other issues that haven't yet appeared. For example, what if a heap allocation from the C++ scudo allocator is freed by C code or vice versa?

vitalybuka added inline comments.Mar 29 2022, 1:08 PM
compiler-rt/lib/scudo/standalone/wrappers_c.cpp
31–32 ↗(On Diff #416584)

I see, I missed cpp file

then probably in wrappers_c.h
#if !SCUDO_ANDROID || !_BIONIC
extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator;
#endif

and remove extern in cpp file

ddcc updated this revision to Diff 418994.Mar 29 2022, 3:01 PM

Move extern declarations to common header

ddcc retitled this revision from [scudo] Remove unused header includes and fix declarations to [scudo] Provide allocator declaration.Mar 29 2022, 3:02 PM
ddcc edited the summary of this revision. (Show Details)
vitalybuka accepted this revision.Mar 29 2022, 4:52 PM
This revision is now accepted and ready to land.Mar 29 2022, 4:52 PM
This revision was landed with ongoing or failed builds.Mar 29 2022, 5:40 PM
This revision was automatically updated to reflect the committed changes.