-bfd_target *
-DEFUN (nlm_object_p, (abfd), bfd * abfd)
-{
- Nlm_External_Fixed_Header x_fxdhdr; /* Nlm file header, external form */
- Nlm_Internal_Fixed_Header *i_fxdhdrp; /* Nlm file header, internal form */
- enum bfd_architecture arch;
-
- /* Read in the fixed length portion of the NLM header in external format. */
-
- if (bfd_read ((PTR) &x_fxdhdr, sizeof (x_fxdhdr), 1, abfd) !=
- sizeof (x_fxdhdr))
- {
- bfd_error = system_call_error;
- return (NULL);
- }
-
- /* Check to see if we have an NLM file by matching the NLM signature. */
-
- if (strncmp (x_fxdhdr.signature, NLM_SIGNATURE, NLM_SIGNATURE_SIZE) != 0)
- {
- bfd_error = wrong_format;
- return (NULL);
- }
-
- /* There's no supported way to discover the endianess of an NLM, so test for
- a sane version number after doing byte swapping appropriate for this
- XVEC. (Hack alert!) */
-
- if (get_word (abfd, (bfd_byte *) x_fxdhdr.version) > 0xFFFF)
- {
- bfd_error = wrong_format;
- return (NULL);
- }
-
- /* There's no supported way to check for 32 bit versus 64 bit addresses,
- so ignore this distinction for now. (FIXME) */
-
- /* Allocate an instance of the nlm_obj_tdata structure and hook it up to
- the tdata pointer in the bfd.
- FIXME: If we later decide this isn't the right format and the bfd
- already had valid tdata, we've just blown away the tdata we wanted
- to save for the right format. */
-
- nlm_tdata (abfd) = (struct nlm_obj_tdata *)
- bfd_zalloc (abfd, sizeof (struct nlm_obj_tdata));
- if (nlm_tdata (abfd) == NULL)
- {
- bfd_error = no_memory;
- return (NULL);
- }
-
- /* FIXME: Any return(NULL) exits below here will leak memory (tdata).
- And a memory leak also means we lost the real tdata info we wanted
- to save, because it was in the leaked memory. */
-
- /* Swap in the rest of the fixed length header. */
-
- i_fxdhdrp = nlm_fixed_header (abfd);
- nlm_swap_fixed_header_in (abfd, &x_fxdhdr, i_fxdhdrp);
-
- if (!nlm_swap_variable_header_in (abfd)
- || !nlm_swap_auxiliary_headers_in (abfd)
- || !add_bfd_section (abfd, NLM_CODE_NAME,
- i_fxdhdrp -> codeImageOffset,
- i_fxdhdrp -> codeImageSize,
- (SEC_CODE | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
- | SEC_RELOC))
- || !add_bfd_section (abfd, NLM_INITIALIZED_DATA_NAME,
- i_fxdhdrp -> dataImageOffset,
- i_fxdhdrp -> dataImageSize,
- (SEC_DATA | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
- | SEC_RELOC))
- || !add_bfd_section (abfd, NLM_UNINITIALIZED_DATA_NAME,
- (file_ptr) 0,
- i_fxdhdrp -> uninitializedDataSize,
- SEC_ALLOC))
- {
- bfd_error = wrong_format;
- return (NULL);
- }
-
- if (nlm_fixed_header (abfd)->numberOfRelocationFixups != 0
- || nlm_fixed_header (abfd)->numberOfExternalReferences != 0)
- abfd->flags |= HAS_RELOC;
- if (nlm_fixed_header (abfd)->numberOfPublics != 0
- || nlm_fixed_header (abfd)->numberOfDebugRecords != 0
- || nlm_fixed_header (abfd)->numberOfExternalReferences != 0)
- abfd->flags |= HAS_SYMS;
-
- arch = nlm_architecture (abfd);
- if (arch != bfd_arch_unknown)
- bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
-
- return (abfd -> xvec);
-}
-
-/* Add a section to the bfd. */
-
-static boolean
-DEFUN (add_bfd_section, (abfd, name, offset, size, flags),
- bfd *abfd AND
- char *name AND
- file_ptr offset AND
- bfd_size_type size AND
- flagword flags)
-{
- asection *newsect;
-
- newsect = bfd_make_section (abfd, name);
- if (newsect == NULL)
- {
- return (false);
- }
- newsect -> vma = 0; /* NLM's are relocatable. */
- newsect -> _raw_size = size;
- newsect -> filepos = offset;
- newsect -> flags = flags;
- newsect -> alignment_power = bfd_log2 (0); /* FIXME */
- return (true);
-}
-
-/* Translate an NLM fixed length file header in external format into an NLM
- file header in internal format. */
-
-static void
-DEFUN (nlm_swap_fixed_header_in, (abfd, src, dst),
- bfd * abfd AND
- Nlm_External_Fixed_Header * src AND
- Nlm_Internal_Fixed_Header * dst)
-{
- memcpy (dst -> signature, src -> signature, NLM_SIGNATURE_SIZE);
- memcpy (dst -> moduleName, src -> moduleName, NLM_MODULE_NAME_SIZE);
- dst -> version =
- get_word (abfd, (bfd_byte *) src -> version);
- dst -> codeImageOffset =
- get_word (abfd, (bfd_byte *) src -> codeImageOffset);
- dst -> codeImageSize =
- get_word (abfd, (bfd_byte *) src -> codeImageSize);
- dst -> dataImageOffset =
- get_word (abfd, (bfd_byte *) src -> dataImageOffset);
- dst -> dataImageSize =
- get_word (abfd, (bfd_byte *) src -> dataImageSize);
- dst -> uninitializedDataSize =
- get_word (abfd, (bfd_byte *) src -> uninitializedDataSize);
- dst -> customDataOffset =
- get_word (abfd, (bfd_byte *) src -> customDataOffset);
- dst -> customDataSize =
- get_word (abfd, (bfd_byte *) src -> customDataSize);
- dst -> moduleDependencyOffset =
- get_word (abfd, (bfd_byte *) src -> moduleDependencyOffset);
- dst -> numberOfModuleDependencies =
- get_word (abfd, (bfd_byte *) src -> numberOfModuleDependencies);
- dst -> relocationFixupOffset =
- get_word (abfd, (bfd_byte *) src -> relocationFixupOffset);
- dst -> numberOfRelocationFixups =
- get_word (abfd, (bfd_byte *) src -> numberOfRelocationFixups);
- dst -> externalReferencesOffset =
- get_word (abfd, (bfd_byte *) src -> externalReferencesOffset);
- dst -> numberOfExternalReferences =
- get_word (abfd, (bfd_byte *) src -> numberOfExternalReferences);
- dst -> publicsOffset =
- get_word (abfd, (bfd_byte *) src -> publicsOffset);
- dst -> numberOfPublics =
- get_word (abfd, (bfd_byte *) src -> numberOfPublics);
- dst -> debugInfoOffset =
- get_word (abfd, (bfd_byte *) src -> debugInfoOffset);
- dst -> numberOfDebugRecords =
- get_word (abfd, (bfd_byte *) src -> numberOfDebugRecords);
- dst -> codeStartOffset =
- get_word (abfd, (bfd_byte *) src -> codeStartOffset);
- dst -> exitProcedureOffset =
- get_word (abfd, (bfd_byte *) src -> exitProcedureOffset);
- dst -> checkUnloadProcedureOffset =
- get_word (abfd, (bfd_byte *) src -> checkUnloadProcedureOffset);
- dst -> moduleType =
- get_word (abfd, (bfd_byte *) src -> moduleType);
- dst -> flags =
- get_word (abfd, (bfd_byte *) src -> flags);
-}
-
-/* Translate an NLM fixed length file header in internal format into
- an NLM file header in external format. */
-
-static void
-DEFUN (nlm_swap_fixed_header_out, (abfd, src, dst),
- bfd * abfd AND
- Nlm_Internal_Fixed_Header * src AND
- Nlm_External_Fixed_Header * dst)
-{
- memcpy (dst -> signature, src -> signature, NLM_SIGNATURE_SIZE);
- memcpy (dst -> moduleName, src -> moduleName, NLM_MODULE_NAME_SIZE);
- put_word (abfd, (bfd_vma) src -> version,
- (bfd_byte *) dst -> version);
- put_word (abfd, (bfd_vma) src -> codeImageOffset,
- (bfd_byte *) dst -> codeImageOffset);
- put_word (abfd, (bfd_vma) src -> codeImageSize,
- (bfd_byte *) dst -> codeImageSize);
- put_word (abfd, (bfd_vma) src -> dataImageOffset,
- (bfd_byte *) dst -> dataImageOffset);
- put_word (abfd, (bfd_vma) src -> dataImageSize,
- (bfd_byte *) dst -> dataImageSize);
- put_word (abfd, (bfd_vma) src -> uninitializedDataSize,
- (bfd_byte *) dst -> uninitializedDataSize);
- put_word (abfd, (bfd_vma) src -> customDataOffset,
- (bfd_byte *) dst -> customDataOffset);
- put_word (abfd, (bfd_vma) src -> customDataSize,
- (bfd_byte *) dst -> customDataSize);
- put_word (abfd, (bfd_vma) src -> moduleDependencyOffset,
- (bfd_byte *) dst -> moduleDependencyOffset);
- put_word (abfd, (bfd_vma) src -> numberOfModuleDependencies,
- (bfd_byte *) dst -> numberOfModuleDependencies);
- put_word (abfd, (bfd_vma) src -> relocationFixupOffset,
- (bfd_byte *) dst -> relocationFixupOffset);
- put_word (abfd, (bfd_vma) src -> numberOfRelocationFixups,
- (bfd_byte *) dst -> numberOfRelocationFixups);
- put_word (abfd, (bfd_vma) src -> externalReferencesOffset,
- (bfd_byte *) dst -> externalReferencesOffset);
- put_word (abfd, (bfd_vma) src -> numberOfExternalReferences,
- (bfd_byte *) dst -> numberOfExternalReferences);
- put_word (abfd, (bfd_vma) src -> publicsOffset,
- (bfd_byte *) dst -> publicsOffset);
- put_word (abfd, (bfd_vma) src -> numberOfPublics,
- (bfd_byte *) dst -> numberOfPublics);
- put_word (abfd, (bfd_vma) src -> debugInfoOffset,
- (bfd_byte *) dst -> debugInfoOffset);
- put_word (abfd, (bfd_vma) src -> numberOfDebugRecords,
- (bfd_byte *) dst -> numberOfDebugRecords);
- put_word (abfd, (bfd_vma) src -> codeStartOffset,
- (bfd_byte *) dst -> codeStartOffset);
- put_word (abfd, (bfd_vma) src -> exitProcedureOffset,
- (bfd_byte *) dst -> exitProcedureOffset);
- put_word (abfd, (bfd_vma) src -> checkUnloadProcedureOffset,
- (bfd_byte *) dst -> checkUnloadProcedureOffset);
- put_word (abfd, (bfd_vma) src -> moduleType,
- (bfd_byte *) dst -> moduleType);
- put_word (abfd, (bfd_vma) src -> flags,
- (bfd_byte *) dst -> flags);
-}
-