The word שמיר shamir has two meanings in the Tanach. In the book of Yeshayahu (5:6, 7:23-25, 9:17, 10:17, 27:4, 32:13) it refers to a kind of thorny plant or thistle. In other books of the prophets (Yirmiyahu 17:1, Yechezkel 3:9, Zechariah 7:12) it has a different meaning - a very hard stone, like a diamond.
Klein suggests they are related. For the thistle meaning he has this entry:
שָׁמִיר ᴵ m.n. Christ’s thorn (mostly occurring together with, שַׁיִת, q.v.). [Related to JAram. שַׁמָּרָא, שֻׁמָּרָא (= fennel), Arab. samur. cp. שֻׁמָּר.]
And for the stone he has the following:
שָׁמִיר ᴵᴵ m.n. 1 smiris corundum, adamant, diamond, emery (in the Bible occurring only Jer. 17:1; Ezek. 3:9; Zech. 7:12). 2 ‘shamir’ (a legendary worm or stone created on the Sabbath eve that could cut any stone). [Related to Syr. שָׁמִירָא (= adamant; emery), Arab. sammūr. שָׁמִיר ᴵᴵ is prob. a special sense development of שָׁמִיר ᴵ and properly denotes orig. a thorn or prickle used as a point for engraving. cp. Jer. 17:1: חַטַּאת יְהוּדָה כְּתוּבָה בְּעֵט בֵּרְזֶל בְּצִפֹּרֶן שָׁמִיר, ‘The sin of Judah is written with a pen of iron, and with the point of a diamond’. Gk. smiris (= emery powder) — whence Gk. smeri, whence It. smeriglio, whence Fren. émeri, whence Eng. emery — is prob. borrowed from שָׁמִיר ᴵᴵ. cp. ‘emery’ in my CEDEL.]
So he concludes that the stone, used for engraving, was similar to the earlier meaning of thorn, and therefore derives from it. And as he notes, this could be a source for the English word "emery," as conceded by the Online Etymology Dictionary:
granular mixture used as an abrasive, late 15c., from French émeri, from Old French esmeril, from Italian smeriglo, from Vulgar Latin *smyrilium, from Greek smyris "abrasive powder" used for rubbing and polishing, probably a non-Greek word, perhaps from a Semitic source. Emery board is attested from 1725.
However, the Encyclopedia Mikrait (entry מלים זרות, page 1078), includes the Hebrew shamir and the Greek smyris in a list of biblical Semitic and Indo-European words that derive from a language family not common to either. It doesn't say where this word (or the others in the list) comes from, but says it's possible that the origin is from Asia Minor, Crete or elsewhere in the Mediterranean.
Neither of the two meanings is in popular use today. The Talmud and midrash (for example Avot 5:6) identified the second meaning not as a stone, but as Klein mentioned, "a legendary worm ... that could cut any stone." This version continued to appear in legends.
The two original meanings inspired the future Israeli prime minister, then Yitzhak Yezernitsky, to change his name to Yitzchak Shamir. As a biography notes, he chose it because it means a "thorn, which stabs and stings: the question is who" and a "hard precious stone capable of breaking steel."
But the most common usage of shamir today is one that Klein doesn't mention: the herb "dill." Almost all dictionaries, if they mention any background at all, will comment that this is the "popular" usage, but the correct Hebrew term for dill is שֶׁבֶת shevet or more specifically שֶׁבֶת רֵיחָנִי shevet reichani. This is the term found in the Mishna. Then why did the people start calling dill shamir?
It seems to be due to a confusion between dill, and the botantically related, and similar looking, "fennel". As Klein noted above, the thistle meaning of shamir is related to the words for fennel in other Semitic languages: shumra in Aramaic and samur in Arabic. This led to the adoption of shumar for fennel in later Hebrew, with shamir available for dill. Here is how each of those spices are defined in the Encyclopedia Judaica, as cited in the Jewish Virtual Library:
The umbelliferous plant Foeniculum vulgare, leaves of which are used as a spice similar to dill, fennel is called gufnan in the Mishnah (Dem. 1:1) and shumar in the Talmud. The Jerusalem Talmud (Dem. 1:1, 21d) states that the Galileans did not consider it a spice, but it was regarded as such in Judah.
Called shevet in the Mishnah, dill is the plant Anethum graveolens used today mainly as a spice in pickled cucumbers. In mishnaic times its foliage, stems, and seed were used as a spice (Ma'as. 4:5), and it was sown for this purpose (Pe'ah 3:2). It is an umbelliferous plant with yellow flowers, which grows wild in the Negev (it is popularly but erroneously called shamir).
From the Chubeza site (a great CSA farm in Israel), the following is added:
Officially, the proper Hebrew name for dill is “shevet reichani” – aromatic “shevet,” but the name this herb somehow ended up with is “Shamir”, a word actually used to describe a thorny wild plant used metaphorically in the Bible when describing a farm overgrown with weeds. Amotz Cohen, teacher and nature explorer, believes that dill is really the “poterium” found primarily in abandoned fields over the country.
Steinberg, in the Milon HaTanach entry for shamir, writes that "in the European exile shamir was used for the plant we call shumar (i.e., fennel)." So perhaps first shamir was used to mean fennel, and then later became designated for dill.
As often happens with "popular" usage, there isn't a definitive answer to when and how the term was adopted, but there is no doubt that in Israel today, shamir = dill, and dill = shamir.
One word that Klein doesn't connect to shamir, and I find this surprising, is masmer מסמר - "nail." Here is his entry:
A collateral form of מַשְׂמֵר; derived from סמר. cp. Aram. מַסְמְרָא (= nail). Arab. mismār is prob. an Aram. loan word
Looking at the root סמר, it's noteworthy that Klein defines it as "to bristle up." To me, "bristle" recalls "thorn" and "nail" echoes the hard stone used for cutting. While Klein doesn't connect them, the Even-Shoshan dictionary does entertain the possibility that they are related. So perhaps this is one more cognate word to consider.