Esempio n. 1
0
// Links the specified elf file.
//
// @param dstFile               The filename of the destination elf file to
//                                  link.
// @param options               Some build options specifying how the elf file
//                                  gets generated.
// @param objFiles              An array of the source .o and .a filenames.
func (c *Compiler) CompileBinary(dstFile string, options map[string]bool,
	objFiles []string, keepSymbols []string, elfLib string) error {

	// Make sure the compiler package info is added to the global set.
	c.ensureLclInfoAdded()

	objList := c.getObjFiles(util.UniqueStrings(objFiles))

	util.StatusMessage(util.VERBOSITY_DEFAULT, "Linking %s\n", dstFile)
	util.StatusMessage(util.VERBOSITY_VERBOSE, "Linking %s with input files %s\n",
		dstFile, objList)

	if elfLib != "" {
		util.StatusMessage(util.VERBOSITY_VERBOSE, "Linking %s with rom image %s\n",
			dstFile, elfLib)
	}

	cmd := c.CompileBinaryCmd(dstFile, options, objFiles, keepSymbols, elfLib)
	_, err := util.ShellCommand(cmd)
	if err != nil {
		return err
	}

	err = writeCommandFile(dstFile, cmd)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
// Calculates the command-line invocation necessary to link the specified elf
// file.
//
// @param dstFile               The filename of the destination elf file to
//                                  link.
// @param options               Some build options specifying how the elf file
//                                  gets generated.
// @param objFiles              An array of the source .o and .a filenames.
//
// @return                      (success) The command string.
func (c *Compiler) CompileBinaryCmd(dstFile string, options map[string]bool,
	objFiles []string, keepSymbols []string, elfLib string) string {

	objList := c.getObjFiles(util.UniqueStrings(objFiles))

	cmd := c.ccPath + " -o " + dstFile + " " + " " + c.cflagsString()

	if elfLib != "" {
		cmd += " -Wl,--just-symbols=" + elfLib
	}

	if c.ldResolveCircularDeps {
		cmd += " -Wl,--start-group " + objList + " -Wl,--end-group "
	} else {
		cmd += " " + objList
	}

	if keepSymbols != nil {
		for _, name := range keepSymbols {
			cmd += " -Wl,--undefined=" + name
		}
	}

	cmd += " " + c.lflagsString()

	/* so we don't get multiple global definitions of the same vartiable */
	//cmd += " -Wl,--warn-common "

	for _, ls := range c.LinkerScripts {
		cmd += " -T " + ls
	}
	if options["mapFile"] {
		cmd += " -Wl,-Map=" + dstFile + ".map"
	}

	return cmd
}