This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Support -z undefs
ClosedPublic

Authored by MaskRay on Sep 11 2019, 9:34 PM.

Details

Summary

-z undefs is the inverse of -z defs. It allows unresolved references
from object files. This can be used to cancel --no-undefined or -z defs.

Event Timeline

MaskRay created this revision.Sep 11 2019, 9:34 PM

Some findings related to the topic. There are two kinds of unresolved references: 1) from object files 2) from shared objects. --unresolved-symbols= toggles both bits while -z (un)defs and --(no-)allow-shlib-undefined toggles one bit, respectively. I personally favor the fine-grained options over --unresolved-symbols=

It seems we can actually model --unresolved-symbols=ignore-in-object-files in terms of --allow-shlib-undefined but I think that is probably unnecessary. I can't find any use of "ignore-in-object-files" outside lld and binutils.

// ld/emultempl/elf32.em
    case 'z':
      if (strcmp (optarg, "defs") == 0)
	link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
      else if (strcmp (optarg, "undefs") == 0)
	link_info.unresolved_syms_in_objects = RM_IGNORE;

// ld/lexsup.c
	case OPTION_NO_UNDEFINED:
	  link_info.unresolved_syms_in_objects
	    = how_to_report_unresolved_symbols;
	  break;
	case OPTION_ALLOW_SHLIB_UNDEFINED:
	  link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
	  break;
	case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
	  link_info.unresolved_syms_in_shared_libs
	    = how_to_report_unresolved_symbols;
	  break;
	case OPTION_UNRESOLVED_SYMBOLS:
	  if (strcmp (optarg, "ignore-all") == 0)
	    {
	      link_info.unresolved_syms_in_objects = RM_IGNORE;
	      link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
	    }
	  else if (strcmp (optarg, "report-all") == 0)
	    {
	      link_info.unresolved_syms_in_objects
		= how_to_report_unresolved_symbols;
	      link_info.unresolved_syms_in_shared_libs
		= how_to_report_unresolved_symbols;
	    }
	  else if (strcmp (optarg, "ignore-in-object-files") == 0)
	    {
	      link_info.unresolved_syms_in_objects = RM_IGNORE;
	      link_info.unresolved_syms_in_shared_libs
		= how_to_report_unresolved_symbols;
	    }
	  else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
	    {
	      link_info.unresolved_syms_in_objects
		= how_to_report_unresolved_symbols;
	      link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
	    }
MaskRay marked an inline comment as done.Sep 11 2019, 11:23 PM
MaskRay added inline comments.
ELF/Driver.cpp
390

Unrelated to this change.

% ld.lld -z max-page-sizez a.o
error: unknown -z value: max-page-sizez
% ld.lld -z common-page-sizez a.o
# No diagnostic "error: unknown -z value: common-page-sizez"
ruiu accepted this revision.Sep 12 2019, 12:50 AM

LGTM

ELF/Driver.cpp
390

Yeah, it is perhaps better to tighten the check a bit to catch that error too.

This revision is now accepted and ready to land.Sep 12 2019, 12:50 AM
This revision was automatically updated to reflect the committed changes.