Skip to content
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

Fix seg fault at initalization in debug mode #1573

Merged
merged 1 commit into from Dec 1, 2016

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Nov 29, 2016

(Fix discovered by J Robert Ray)

When using gcc 4.8 on centos7, with debug compile, in a certain app, we get core dumps involving SIGSEGV in __memcmp_sse4_1 deep inside operator.

We don't understand it, and in fact suspect a compiler bug. Can't reproduce on other platforms or compiler releases. Sweep it under the rug with this patch, that seems to work around it, though we admit we don't know why.

@@ -280,8 +280,14 @@ class TagMap {
for (int i = 0; tag_table[i].tifftag >= 0; ++i) {
const EXIF_tag_info *eti = &tag_table[i];
m_tagmap[eti->tifftag] = eti;
if (eti->name)
m_namemap[eti->name] = eti;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I like this solution. It feels like something fishy is going on here. What is the value of eti->name when it crashes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this one of those "static initialization order" fiasco type bugs? What if you wrap both tables in a function so they can be initialized on first use instead of on program startup?

Copy link
Contributor

Choose a reason for hiding this comment

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

Finally -- I don't think std::string is needed at all here. Can't you swap for string_view instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Finally^2 -- these table seem small enough that I wonder if std::map is needed at all. I bet a good old linear search would run just as fast or faster.

@lgritz
Copy link
Collaborator Author

lgritz commented Nov 29, 2016

OK, let me take another stab at it. I also suspected initialization order fiasco.

When using gcc 4.8 on centos7, with debug compile, in a certain app, we
get core dumps involving SIGSEGV in __memcmp_sse4_1 deep inside
operator[](std::string&&).

We suspect it's the old "initialization order fiasco." Wrapping the tag
table as a static within a function that returns its reference seems to
fix things. I also switched from strings to string_view for the table
keys.
@lgritz
Copy link
Collaborator Author

lgritz commented Dec 1, 2016

Updated the patch. Moved the static init of the tables into functions that return their reference. Seems to work. I also switched the std::string map keys to string_view.

@fpsunflower
Copy link
Contributor

LGTM!

I still think a linear search would probably be fine too (and maybe faster?) But I don't have a good sense of how this is used, or if these tables could get bigger in the future.

@lgritz lgritz merged commit b7d7084 into AcademySoftwareFoundation:RB-1.7 Dec 1, 2016
@lgritz lgritz deleted the lg-exifinit branch December 1, 2016 05:46
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Dec 1, 2016
…on#1573)

When using gcc 4.8 on centos7, with debug compile, in a certain app, we
get core dumps involving SIGSEGV in __memcmp_sse4_1 deep inside
operator[](std::string&&).

We suspect it's the old "initialization order fiasco." Wrapping the tag
table as a static within a function that returns its reference seems to
fix things. I also switched from strings to string_view for the table
keys.
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.

None yet

2 participants