Page MenuHomeFreeBSD

Workaround for crtbegin.o or crtend.o not being included into the link
ClosedPublic

Authored by kib on Mon, Jan 27, 8:42 PM.
Tags
None
Referenced Files
F108956553: D48700.id150050.diff
Wed, Jan 29, 11:26 PM
F108949752: D48700.id150086.diff
Wed, Jan 29, 10:06 PM
Unknown Object (File)
Wed, Jan 29, 9:03 PM
Unknown Object (File)
Wed, Jan 29, 8:19 PM
Unknown Object (File)
Wed, Jan 29, 8:02 PM
Unknown Object (File)
Wed, Jan 29, 10:48 AM
Unknown Object (File)
Tue, Jan 28, 11:27 PM
Unknown Object (File)
Tue, Jan 28, 2:43 AM
Subscribers

Details

Summary
crtbegin: accurately check for the end of .dtors

not relying only on the end section marker, but also checking for the
section size when iterating.

Reported by:    kargl
Analyzed by:    dim

crtbegin: accurately check for the start of .ctors

For the hypothetic situation where crtbegin.o is not linked into the
binary, but crtend.o is, which results in the missing starting sentinel
in the ctors array, be careful to not iterate past the start of the
section.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib requested review of this revision.Mon, Jan 27, 8:42 PM

LGTM

lib/csu/common/crtbegin.c
88

So we expect that if .dtors is nonexistent, that both startof and sizeof are zero?

This revision is now accepted and ready to land.Mon, Jan 27, 9:03 PM
lib/csu/common/crtbegin.c
88

They are weak. Why the question?

lib/csu/common/crtbegin.c
88

I was just wondering what would happen if one of them was zero, but the other wasn't. But that is probably extremely unlikely. :)

kib marked 2 inline comments as done.Mon, Jan 27, 10:04 PM
kib added inline comments.
lib/csu/common/crtbegin.c
88

I added the zero check to work around a possible case that linker does not support these .startof. and .sizeof. symbols. We do always have the .dtors section if this file is ever compiled/linked.

How difficult would it be to write a test for this?

kib marked an inline comment as done.Tue, Jan 28, 11:05 AM

How difficult would it be to write a test for this?

It is relatively cumbersome. The mock for crtbegin and crtend would need to be provided, containing everything but the CTOR_LIST and DTOR_END elements. I.e. it would need to make a copy of the current .c files, and then explicitly write out linker invocation to use that instead of csu from /usr/lib.

We might be able to use objcopy to remove them from the existing binary, but the test shouldn't block a fix.