Opened 18 months ago

Last modified 13 months ago

#66087 assigned defect

got fails to build: Undefined symbols: "_memset_s"

Reported by: barracuda156 Owned by: artkiver (グレェ)
Priority: Normal Milestone:
Component: ports Version: 2.8.0
Keywords: Cc:
Port: got

Description

Undefined symbols:
  "_memset_s", referenced from:
      _recallocarray in libopenbsd-compat.a(recallocarray.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [got-fetch-pack] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_got/got/work/got-portable-0.77/libexec/got-fetch-pack'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_got/got/work/got-portable-0.77/libexec'
make: *** [all-recursive] Error 1

Same failure is confirmed on 10.6.8 Rosetta (gcc-4.2, gcc12) and 10.8.5 (clang, gcc12).

Attachments (1)

Screenshot 2022-10-28 at 01.51.58.png (244.9 KB) - added by artkiver (グレェ) 18 months ago.
Known working and not working got OS versions.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 18 months ago by barracuda156

Adding -D__STDC_WANT_LIB_EXT1__=1 to cppflags or cflags fails to help.

Last edited 18 months ago by barracuda156 (previous) (diff)

comment:2 Changed 18 months ago by artkiver (グレェ)

Hi @baracuda156 thanks for the bug report.

To be honest, I am uncertain if I will be able to be of much help on this. While I do have some Leopard vintage G4 PowerBooks in storage, I am not sure if I have anything older than perhaps Catalina running on any of my personal systems easily accessible? Moreover, since the port for gameoftrees was created, I don't think the details view (e.g. https://ports.macports.org/port/got/details/) has ever shown got building successfully on any version of the OS older than High Sierra.

In other words: this may be a more challenging bug to address than I personally can solve. However, if you or others can find any workable patches, the upstream project is pretty cooperative in getting such things committed.

Changed 18 months ago by artkiver (グレェ)

Known working and not working got OS versions.

comment:3 in reply to:  2 Changed 18 months ago by barracuda156

Replying to artkiver:

Thank you for responding. I will try fixing it.

comment:4 Changed 18 months ago by kencu (Ken)

memset_s was not available until MacOSX 10.9:

errno_t	memset_s(void *__s, rsize_t __smax, int __c, rsize_t __n) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);

but it does not look hard to write a similar function, so it could easily be put into legacysupport.

https://github.com/apple/darwin-xnu/blob/main/osfmk/kern/memset_s.c

comment:5 Changed 18 months ago by artkiver (グレェ)

@barracuda156 You are most welcome. I would say as far as other resources, Thomas Adam is the got-portable maintainer, albeit as far as I know, he mostly focuses on Linux build issues but was still cooperative with me when -portable had an issue introduced after adding a diff for compatibility with Homebrew, which caused challenges with the MacPorts assumptions. There is also an IRC channel #gameoftrees on libera.chat and a low volume mailing list (more information on that here: https://lists.openbsd.org/cgi-bin/mj_wwwusr?user=&passw=&func=lists-long-full&extra=gameoftrees ) which may be helpful?

@kencu if that methodology is viable, that would be great! Thanks for the extra set of eyeballs.

comment:6 Changed 18 months ago by kencu (Ken)

the other way to approach this is for upstream to test for and only use memset_s if the symbol exists, otherwise fall back (presumably) to memset.

comment:7 in reply to:  6 Changed 18 months ago by barracuda156

Replying to kencu:

the other way to approach this is for upstream to test for and only use memset_s if the symbol exists, otherwise fall back (presumably) to memset.

samba4 has this:

#ifndef HAVE_MEMSET_S
# ifndef RSIZE_MAX
#  define RSIZE_MAX (SIZE_MAX >> 1)
# endif

int rep_memset_s(void *dest, size_t destsz, int ch, size_t count)
{
	if (dest == NULL) {
		return EINVAL;
	}

	if (destsz > RSIZE_MAX ||
	    count > RSIZE_MAX ||
	    count > destsz) {
		return ERANGE;
	}

#if defined(HAVE_MEMSET_EXPLICIT)
	memset_explicit(dest, destsz, ch, count);
#else /* HAVE_MEMSET_EXPLICIT */
	memset(dest, ch, count);
# if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
	/* See http://llvm.org/bugs/show_bug.cgi?id=15495 */
	__asm__ volatile("" : : "g"(dest) : "memory");
# endif /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
#endif /* HAVE_MEMSET_EXPLICIT */

	return 0;
}
#endif /* HAVE_MEMSET_S */

And postgresql has:

#if defined(HAVE_MEMSET_S)

void
explicit_bzero(void *buf, size_t len)
{
	(void) memset_s(buf, len, 0, len);
}

#elif defined(WIN32)

void
explicit_bzero(void *buf, size_t len)
{
	(void) SecureZeroMemory(buf, len);
}

#else

/*
 * Indirect call through a volatile pointer to hopefully avoid dead-store
 * optimisation eliminating the call.  (Idea taken from OpenSSH.)  We can't
 * assume bzero() is present either, so for simplicity we define our own.
 */

static void
bzero2(void *buf, size_t len)
{
	memset(buf, 0, len);
}

static void (*volatile bzero_p) (void *, size_t) = bzero2;

void
explicit_bzero(void *buf, size_t len)
{
	bzero_p(buf, len);
}

#endif

Anything is this usable? A check for HAVE_MEMSET_S is easily added to configure.

comment:8 Changed 18 months ago by artkiver (グレェ)

As a bit of an aside, got 0.78 was released and I am prepping a PR for that. It won't address the issues raised in this ticket, but I thought I would keep you apprised.

comment:9 Changed 18 months ago by artkiver (グレェ)

Still somewhat of an aside, I submitted a PR for got 0.79 and that was merged. I was also looking into some other tickets, and there was mention of legacy support devel (https://ports.macports.org/port/legacy-support-devel/) perhaps that might be a good place to introduce the HAVE_MEMSET_S function and test it on older OSes to see if that may help with got?

comment:10 in reply to:  9 Changed 13 months ago by barracuda156

Replying to artkiver:

Still somewhat of an aside, I submitted a PR for got 0.79 and that was merged. I was also looking into some other tickets, and there was mention of legacy support devel (https://ports.macports.org/port/legacy-support-devel/) perhaps that might be a good place to introduce the HAVE_MEMSET_S function and test it on older OSes to see if that may help with got?

Do you have a suggestion how to better write it?

comment:11 in reply to:  4 ; Changed 13 months ago by barracuda156

Replying to kencu:

but it does not look hard to write a similar function, so it could easily be put into legacysupport.

https://github.com/apple/darwin-xnu/blob/main/osfmk/kern/memset_s.c

Will this work?

https://github.com/regehr/sudo-1.8.13/blob/master/lib/util/memset_s.c

comment:12 in reply to:  11 ; Changed 13 months ago by artkiver (グレェ)

Possibly! To be honest, I never got around to digging up any older laptops from my storage unit to test even the earlier suggestions about augmenting legacy-support or legacy-support-devel and had kind of forgotten about it until the Trac update reminded me. I just reached out to Thomas Adams (who heads up the -portable branch of Got) to see if maybe a better approach would be to address this upstream in the event that there may be people running older Mac OS versions who don't want to run MacPorts.

Replying to barracuda156:

Replying to kencu:

but it does not look hard to write a similar function, so it could easily be put into legacysupport.

https://github.com/apple/darwin-xnu/blob/main/osfmk/kern/memset_s.c

Will this work?

https://github.com/regehr/sudo-1.8.13/blob/master/lib/util/memset_s.c

comment:13 in reply to:  12 Changed 13 months ago by barracuda156

Replying to artkiver:

I just reached out to Thomas Adams (who heads up the -portable branch of Got) to see if maybe a better approach would be to address this upstream in the event that there may be people running older Mac OS versions who don't want to run MacPorts.

Thank you!

Note: See TracTickets for help on using tickets.