Closed Bug 181936 Opened 22 years ago Closed 21 years ago

libpng conflicts with system libpng in static builds

Categories

(Core :: Graphics: ImageLib, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: bryner, Assigned: glennrp+bmo)

References

Details

Attachments

(1 file, 1 obsolete file)

It's fairly easy to get a libpng runtime version conflict if you use a static
build of Mozilla or Phoenix with a gtk theme engine (i.e. the pixmap engine)
that dlopen()s the system libpng library.  The main problem is that calls from
inside the system libpng use the normal symbol scope lookup and end up finding
_some_ of the symbols in the mozilla binary.  The symptom is that png's fail to
load for the gtk theme engine, which will cause pixmap backgrounds not to show
up for nsITheme-drawn elements.

It should be possible to fix this in libpng by not using exported symbols
internally, but since we can't really change the system libpng's that are out
there, we need to come up with another solution.

Hiding the libpng symbols in the final binary sounds appealing, but the linker
doesn't support doing that.  A solution that would work is to rename (via
#defines, likely) the libpng symbols that Mozilla uses.  That prevents any
possibility of the system libpng using those symbols by mistake.

This may affect libjpeg as well, but I haven't tested it yet.
Sounds sickingly familiar to bug 119934 though I'd wonder why you don't just use
the system png library in this case (assuming that it's a compatible version).

That's the problem.  We don't know if it will be compatible on the system the
build runs on.

I wonder if it's time to revisit system libpng as an external requirement....
> The main problem is that calls from
> inside the system libpng use the normal symbol scope lookup and end up finding
> _some_ of the symbols in the mozilla binary.

Hrm.  Have you tried building w/o using -Bsymbolic?  Or is the problem that the
system version of libpng should be built using -Bsymbolic and isn't?  If we made
the in-tree version of libpng dynamic instead of static, would that "fix" the
problem or just cause new problems as the theme engine would use the symbols
entirely from the moz version of libpng instead of the system version?

Having libpng be an external dependency seems like the cleanest solution.
If the system libpng was built with -Bsymbolic, that would fix the problem. 
However, there's not much we can do about that.

We could build Mozilla's png decoder as a dynamic component with libpng
statically linked; that would keep the symbols from being visible to the system
libpng.  But I don't really want to make even more things forced-dynamic in a
static build.

Are versions of libpng more recent than the one we're using fully backwards
compatible?  Are there any custom fixes that we need?
http://lxr.mozilla.org/mozilla/source/modules/libimg/png/MOZCHANGES

Recent versions are compatible for the moment as tor recently landed version
1.2.5.  But seeing as we were back at 1.0.x for 3 yrs or so, there's a good
chance that we'll be incompatible in the future.
What about modifying the libpng.h/libjpeg.h header file(s) and do a |#define
foo(a,b) moz_foo((a), (b))| to work around the symbol issue ?
The libpng distributed with mozilla is incompatible with the system libpng-1.2.5
because it is no longer pristine.  Unused functions and some unused members of
the png_ptr and png_info structs were removed in bug #208607.  The library still
calls itself version 1.2.5, though.
> What about modifying the libpng.h/libjpeg.h header file(s) and do a |#define
> foo(a,b) moz_foo((a), (b))| to work around the symbol issue ?

Why not simply #define foo moz_foo ?  I tried this in a private copy of libpng
and it seems to work.

Glenn Randers-Pehrson wrote:
> > What about modifying the libpng.h/libjpeg.h header file(s) and do a |#define
> > foo(a,b) moz_foo((a), (b))| to work around the symbol issue ?
>
> Why not simply #define foo moz_foo ?  I tried this in a private copy of libpng
> and it seems to work.

That would work, too - however I prefer the first form since it allows to catch
syntax errors (for example "wrong number of function arguments" etc.) without
pain.
Blocks: 119934
Reassigning to myself and setting as blocker of bug#119934.  It's almost a dupe
but I'd prefer to work on libpng separately.
Assignee: bryner → randeg
accepting bug.
Status: NEW → ASSIGNED
Blocks: 208607
Comment on attachment 128779 [details] [diff] [review]
Patch to prefix all libpng exported symbols with "moz_"

r?
Attachment #128779 - Flags: review?(pavlov)
Attachment #128779 - Flags: superreview?(tor)
Attachment #128779 - Flags: review?(pavlov)
Attachment #128779 - Flags: review+
Attachment #128779 - Flags: superreview?(tor) → superreview+
Changed the prefix from "moz_png" to "MOZ_PNG" to be consistent with
bug #119934 which uses "MOZ_EXP" for expat externals.
Attachment #128779 - Attachment is obsolete: true
Oops, expat uses "MOZ_XML" not "MOZ_EXP" but the argument still applies.

Does this need r/sr again for this trivial change?
Comment on attachment 134319 [details] [diff] [review]
Patch to prefix all libpng externals with MOZ_PNG

sr=bryner for the trivial change, and I wouldn't bother with a second review.
Attachment #134319 - Flags: superreview?
Comment on attachment 134319 [details] [diff] [review]
Patch to prefix all libpng externals with MOZ_PNG

sr=bryner for the trivial change, and I wouldn't bother with a second review.
Attachment #134319 - Flags: superreview+
Comment on attachment 134319 [details] [diff] [review]
Patch to prefix all libpng externals with MOZ_PNG

oops, i confused bugzilla
Attachment #134319 - Flags: superreview?
Checked in.  Thanks for the patch Glenn.
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: